2017 © Pedro Peláez
 

library factory-generator

Laravel 5 Model Factory Generator.

image

rymanalu/factory-generator

Laravel 5 Model Factory Generator.

  • Saturday, September 2, 2017
  • by rymanalu
  • Repository
  • 1 Watchers
  • 15 Stars
  • 1,965 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 4 Forks
  • 1 Open issues
  • 6 Versions
  • 18 % Grown

The README.md

Laravel 5 Model Factory Generator

This package offers a lazy way to create a new model factory files, since Laravel has no Artisan command to generate it., (*1)

Installation

First, install this package via the Composer package manager:, (*2)

composer require rymanalu/factory-generator

Next, you should add the FactoryGeneratorServiceProvider to the providers array of your config/app.php configuration file:, (*3)

Rymanalu\FactoryGenerator\FactoryGeneratorServiceProvider::class,

Now, you should be able to generate a new model factory file by executing php artisan make:factory command., (*4)

Usage

php artisan make:factory accept one argument: the model class name with the namespace. Make sure the model is already exists before execute this command., (*5)

Example:, (*6)

php artisan make:factory "App\Post"

The command will generate a file named PostFactory.php in /path/to/your-laravel-project/database/factories directory:, (*7)

<?php

use App\Post;
use Faker\Generator as Faker;

$factory->define(Post::class, function (Faker $faker) {
    //
});

This command also using the fillable array of the model and pair all of fillable values to $faker->word as default (you can change it to the proper Faker Formatters or other value later) in the generated model factory., (*8)

For example, if the App\Post has fillable array like this:, (*9)

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class Post extends Model
{
    /**
     * The attributes that are mass assignable.
     *
     * @var array
     */
    protected $fillable = [
        'text',
    ];
}

Then, the command will generate the PostFactory.php like this:, (*10)

<?php

use App\Post;
use Faker\Generator as Faker;

$factory->define(Post::class, function (Faker $faker) {
    return [
        'text' => $faker->word,
    ];
});

The Versions

02/09 2017

1.0.x-dev

1.0.9999999.9999999-dev https://github.com/rymanalu/factory-generator

Laravel 5 Model Factory Generator.

  Sources   Download

MIT

The Requires

 

by Roni Yusuf Manalu

laravel generator model factory model factory

31/03 2017

dev-master

9999999-dev https://github.com/rymanalu/factory-generator

Laravel 5 Model Factory Generator.

  Sources   Download

MIT

The Requires

 

by Roni Yusuf Manalu

laravel generator model factory model factory

25/03 2017

v1.0.2

1.0.2.0 https://github.com/rymanalu/factory-generator

Laravel 5 Model Factory Generator.

  Sources   Download

MIT

The Requires

 

by Roni Yusuf Manalu

laravel generator model factory model factory

24/03 2017

v1.0.1

1.0.1.0 https://github.com/rymanalu/factory-generator

Laravel 5 Model Factory Generator.

  Sources   Download

MIT

The Requires

 

by Roni Yusuf Manalu

laravel generator model factory model factory

24/03 2017

v1.0.0

1.0.0.0 https://github.com/rymanalu/factory-generator

Laravel 5 Model Factory Generator.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Roni Yusuf Manalu

laravel generator model factory model factory

24/03 2017

v0.1.0

0.1.0.0 https://github.com/rymanalu/factory-generator

Laravel 5 Model Factory Generator.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Roni Yusuf Manalu

laravel generator model factory model factory