Skip to main content
Quick Tip

Specify dependencies in the run() method

You can specify dependencies in the run() method of your seeder.

class DatabaseSeeder extends Seeder
{
public function run()
{
$user = User::factory()->create();
 
$this->callWith(EventSeeder::class, [
'user' => $user
]);
}
}
class EventSeeder extends Seeder
{
public function run(User $user)
{
Event::factory()
->when($user, fn($f) => $f->for('user'))
->for(Program::factory())
->create();
}
}

Tip given by @justsanjit

Enjoyed This Tip?

Get access to all premium tutorials, video and text courses, and exclusive Laravel resources. Join our community of 10,000+ developers.

Recent Courses

[NEW] Building a Typical Laravel SaaS

13 lessons
1 h 58 min

Filament 4 From Scratch

28 lessons
2 h 25 min

NativePHP: Build Mobile App with Laravel

11 lessons
2 h 2 min read

We'd Love Your Feedback

Tell us what you like or what we can improve

Feel free to share anything you like or dislike about this page or the platform in general.