seeder
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| seeder [2020/12/23 19:08] – chifek | seeder [2023/09/14 06:06] (current) – external edit 127.0.0.1 | ||
|---|---|---|---|
| Line 76: | Line 76: | ||
| Within the `DatabaseSeeder` class, you may use the `call` method to execute additional seed classes. Using the call method allows you to break up your database seeding into multiple files so that no single seeder class becomes too large. The `call` method accepts an array of seeder classes that should be executed: | Within the `DatabaseSeeder` class, you may use the `call` method to execute additional seed classes. Using the call method allows you to break up your database seeding into multiple files so that no single seeder class becomes too large. The `call` method accepts an array of seeder classes that should be executed: | ||
| + | < | ||
| + | /** | ||
| + | * Run the database seeders. | ||
| + | * | ||
| + | * @return void | ||
| + | */ | ||
| + | public function run() | ||
| + | { | ||
| + | $this-> | ||
| + | UserSeeder:: | ||
| + | PostSeeder:: | ||
| + | CommentSeeder:: | ||
| + | ]); | ||
| + | } | ||
| + | </ | ||
| + | |||
| + | **Running Seeders** | ||
| + | |||
| + | You may execute the `db:seed` Artisan command to seed your database. By default, the `db:seed` command runs the `Database\Seeders\DatabaseSeeder` class, which may in turn invoke other seed classes. However, you may use the --class option to specify a specific seeder class to run individually: | ||
| + | |||
| + | < | ||
| + | php artisan db:seed | ||
| + | |||
| + | php artisan db:seed --class=UserSeeder | ||
| + | </ | ||
| + | |||
| + | You may also seed your database using the `migrate: | ||
| + | |||
| + | < | ||
| + | php artisan migrate: | ||
| + | </ | ||
| + | |||
| + | **Forcing Seeders To Run In Production** | ||
| + | |||
| + | Some seeding operations may cause you to alter or lose data. In order to protect you from running seeding commands against your production database, you will be prompted for confirmation before the seeders are executed in the `production` environment. To force the seeders to run without a prompt, use the `--force` flag: | ||
| + | |||
| + | < | ||
seeder.1608750494.txt.gz · Last modified: 2023/09/14 06:06 (external edit)