Coding my way

5 years ago in PHP, Laravel, Package Development · 1 MIN READ

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

Remember, running 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


  db:seed [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


Miklós Galicz

I'm a hobbyist who managed to become a professional web developer who specializes in Laravel and Vue.js, also the Spice must flow.
comments powered by Disqus

© 2019 DevBlog