Creating Database Seeder for packages in Laravel 5.1
Laravel 4.2 provided a clear-cut way for running database seeds provided by third-party packages. Not much has changed since the coming of Laravel 5.1
artisan commands with the
--help option will list all available arguments and options for the selected command.
This also applies to the
db:seed command as well. Running the command will yield the following results:
vagrant@homestead:~/projects-community/crud-tester\$ php artisan db:seed --help Usage: db:seed [options] Options: --class[=CLASS] The class name of the root seeder [default: \"DatabaseSeeder\"] --database[=DATABASE] The database connection to seed --force Force the operation to run when in production. -h, --help Display this help message -q, --quiet Do not output any message -V, --version Display this application version --ansi Force ANSI output --no-ansi Disable ANSI output -n, --no-interaction Do not ask any interactive question --env[=ENV] The environment the command should run under. -v|vv|vvv, --verbose Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug
As you can see Laravel still provides the
--class option, with which you can tell artisan which Class to use to seed the database. This defaults to the
DatabseSeeder class located in your
project/database/seeds folder, but you can provide class names with namespaces as well to load your package's migrations as well.
An example of this would be:
php artisan db:seed --class=BlackfyreStudio\\CRUD\\DatabaseSeeder