-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
adds ColumnShouldBeIgnored class, adds readme
- Loading branch information
Ilya Sakovich
committed
Mar 7, 2019
1 parent
920cec0
commit b47bf08
Showing
3 changed files
with
97 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,63 @@ | ||
# Laravel Populated Factory | ||
# Laravel Populated Factory | ||
|
||
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 coderello/laravel-populated-factory | ||
``` | ||
|
||
The package will automatically register itself. | ||
|
||
## Usage | ||
|
||
```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 | ||
<?php | ||
|
||
use Faker\Generator as Faker; | ||
|
||
/** @var $factory \Illuminate\Database\Eloquent\Factory */ | ||
|
||
$factory->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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<?php | ||
|
||
namespace Coderello\PopulatedFactory; | ||
|
||
use Doctrine\DBAL\Schema\Column; | ||
|
||
class ColumnShouldBeIgnored | ||
{ | ||
public function __invoke(Column $column): bool | ||
{ | ||
if ($column->getAutoincrement()) { | ||
return true; | ||
} | ||
|
||
return false; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters