Laravel 9 is fresh out the door, and it contains a small contribution of mine: a new callOnce method for database seeders. It solves a problem with seeders I’ve had for a long time, and thanks to http://twitter.com/brendt_gd/status/1465210141192634370 and https://twitter.com/rubenvanassche’s input I was able to propose a lightweight solution.

There are users (than can log in and publish posts), posts, pages, and categories.

You could have PostSeeder seed its own users and categories, but then DatabaseSeeder is seeding a bunch of unnecessary data.

class PostSeeder extends Seeder { public function run() { $this->callOnce([ UserSeeder::class, CategorySeeder::class, ]); }} class PageSeeder extends Seeder { public function run() { $this->callOnce([ CategorySeeder::class, ]); }}
Newsletter

Get the latest Laravel/PHP jobs, events and curated articles straight to your inbox, once a week

Glimpse streamlines Laravel development by seamlessly deploying GitHub pull requests to preview environments with the help of Laravel Forge. Glimpse streamlines Laravel development by seamlessly deploying GitHub pull requests to preview environments with the help of Laravel Forge.
Fathom Analytics | Fast, simple and privacy-focused website analytics. Fathom Analytics | Fast, simple and privacy-focused website analytics.
Shirts painstakingly handcrafted by under-caffeinated developers. Shirts painstakingly handcrafted by under-caffeinated developers.
Community Partners