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

Fathom Analytics | Fast, simple and privacy-focused website analytics. Fathom Analytics | Fast, simple and privacy-focused website analytics.
Achieve superior email deliverability with ToastMail! Our AI-driven tool warms up inboxes, monitors reputation, and ensures emails reach their intended destination. Sign up today for a spam-free future. Achieve superior email deliverability with ToastMail! Our AI-driven tool warms up inboxes, monitors reputation, and ensures emails reach their intended destination. Sign up today for a spam-free future.
Community Partners