Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/rymanalu/factory-generator
Laravel 5 Model Factory Generator
https://github.com/rymanalu/factory-generator
factory laravel laravel-model model
Last synced: about 1 month ago
JSON representation
Laravel 5 Model Factory Generator
- Host: GitHub
- URL: https://github.com/rymanalu/factory-generator
- Owner: rymanalu
- License: mit
- Created: 2017-03-23T06:50:22.000Z (over 7 years ago)
- Default Branch: 1.0
- Last Pushed: 2017-09-02T17:54:40.000Z (over 7 years ago)
- Last Synced: 2024-08-13T12:57:04.541Z (4 months ago)
- Topics: factory, laravel, laravel-model, model
- Language: PHP
- Size: 8.79 KB
- Stars: 17
- Watchers: 2
- Forks: 4
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
- awesome-indo-projects - Laravel 5 Model Factory Generator - Generate a new model factory using Artisan command. (Laravel)
- awesome-indonesia-repo - Laravel 5 Model Factory Generator - Generate a new model factory using Artisan command. (Laravel)
README
# Laravel 5 Model Factory Generator
This package offers a lazy way to create a new model factory files, since Laravel (< 5.5) have no Artisan command to generate it.
## Installation
First, install this package via the Composer package manager:
```
composer require rymanalu/factory-generator
```Next, you should add the `FactoryGeneratorServiceProvider` to the `providers` array of your `config/app.php` configuration file:
```php
Rymanalu\FactoryGenerator\FactoryGeneratorServiceProvider::class,
```
Now, you should be able to generate a new model factory file by executing `php artisan make:factory` command.## Usage
`php artisan make:factory` accept one argument: the model class name with the namespace. Make sure the model is already exists before executing this command.Example:
```
php artisan make:factory "App\Post"
```
The command will generate a file named `PostFactory.php` in `/path/to/your-laravel-project/database/factories` directory:```php
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](https://github.com/fzaninotto/Faker) Formatters or other value later) in the generated model factory.For example, if the `App\Post` has fillable array like this:
```php
define(Post::class, function (Faker $faker) {
return [
'text' => $faker->word,
];
});
```