Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/coderello/laravel-populated-factory
🏭 An easy way to generate populated factories for models.
https://github.com/coderello/laravel-populated-factory
Last synced: about 2 months ago
JSON representation
🏭 An easy way to generate populated factories for models.
- Host: GitHub
- URL: https://github.com/coderello/laravel-populated-factory
- Owner: coderello
- License: mit
- Created: 2019-03-07T21:53:37.000Z (over 5 years ago)
- Default Branch: 1.0
- Last Pushed: 2020-11-18T11:53:04.000Z (almost 4 years ago)
- Last Synced: 2024-07-19T01:06:32.333Z (2 months ago)
- Language: PHP
- Homepage:
- Size: 22.5 KB
- Stars: 249
- Watchers: 6
- Forks: 17
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE.md
Awesome Lists containing this project
README
Laravel Populated Factory provides an easy way to generate populated factories for models according to types & names of their columns.
## Install
You can install this package via composer using this command:
```php
composer require --dev coderello/laravel-populated-factory
```The package will automatically register itself.
## Usage
The only thing you need to do in order to generate a populated factory is to execute this command:
```php
php artisan make:populated-factory User
```> This command assumes that the `User` model is in the `App` namespace. If your models are situated in another namespace (e.g. `App\Models`) you should specify them either as `Models\\User` or `\\App\\Models\\User`.
Here is the populated factory generated for the `User` model according to its column types & names.
```php
define(\App\User::class, function (Faker $faker) {
return [
'name' => $faker->name,
'email' => $faker->unique()->safeEmail,
'email_verified_at' => $faker->dateTime,
'password' => '$2y$10$uTDnsRa0h7wLppc8/vB9C.YqsrAZwhjCgLWjcmpbndTmyo1k5tbRC',
'remember_token' => $faker->sha1,
'created_at' => $faker->dateTime,
'updated_at' => $faker->dateTime,
];
});
```If you want a custom name for the factory, you need to pass it as the second argument like so:
```bash
php artisan make:populated-factory User AdminFactory
```If you want to override the existent factory, you need to use `--force` flag like so:
```bash
php artisan make:populated-factory User --force
```## Contributing
Please see [CONTRIBUTING](CONTRIBUTING.md) for details.
## License
The MIT License (MIT). Please see [License File](LICENSE.md) for more information.