Skip to content
This repository has been archived by the owner on Jun 19, 2023. It is now read-only.

Shortcut artisan command for running different seeder classes

License

Notifications You must be signed in to change notification settings

arbitraer/laravel-fresh-seeds

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

A shortcut structure and command for seeder classes

MIT Licensed

This Laravel package adds the php artisan fresh command with an editable default seeder class, so you can call your most important seeds when running a fresh migration much more quicker.

Installation

Install via composer

composer require arbitraer/laravel-fresh-seeds

Configuration

After installation you can publish the config file:

php artisan vendor:publish --provider="Arbitraer\FreshSeeds\FreshSeedsServiceProvider" --tag="config"

Usage

To seed the default Laravel database seeder database/seeders/DatabaseSeeder.php with a fresh migration:

php artisan fresh

Creating a suite

If you find yourself calling different seeders for different cases (testing, demoing or setting up the application) with a fresh migration, you can create dedicated seeder suites in the app/config/fresh-seeds.php config file, referencing a seeder class in database/seeders/ and then run a fast and easy to remember command:

...
    'suites' => [
        'basic' => 'DatabaseSeeder',
        'demo'  => 'DemoDatabaseSeeder'
    ],
...

Then you can use the --suite= or -s option with this command to specify the desired seeder suite:

php artisan fresh -s demo

Everytime you add a new seeder suite you'll have to perform a composer dump autoload:

composer dump-autoload

Changing the default suite

You can change the default suite to be run when calling php artisan fresh by changing the default_suite setting in the fresh-seeds.php config file or by adding the SEED_SUITE_DEFAULT variable to your .env file:

SEED_SUITE_DEFAULT=demo

Suggested structure

It can make sense, to move the table seeds into single files within a seperate folder in the database/seeders/ directory and then call them from your seeder suite classes. This way you can easily reuse them from different suites. For example:

.
├── ...
├── database
│   ├── ...
│   ├── ...
│   └── seeders
│      ├── DatabaseSeeder.php
│      ├── DemoDatabaseSeeder.php       # custom seeder suite that calls the required table seeds
│      └── seeds
│           └── PostTableSeeder.php     # a post table seed callable by different seeder suites
│           └── ...
└── ...

To get you started with this structure, this package provides some example files and folders according to the examples in the published config file:

php artisan vendor:publish --provider="Arbitraer\FreshSeeds\FreshSeedsServiceProvider" --tag="suites"

Testing

composer test

Credits

arbiträr – Digital agency for web development in Flensburg, Germany

License

The MIT License (MIT). Please see License File for more information.

About

Shortcut artisan command for running different seeder classes

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages