مصانع متقدمة:
الحالات
public function suspended(): static
{
return $this->state(['status' => 'suspended']);
}
User::factory()->suspended()->create();العلاقات
User::factory()
->has(Post::factory()->count(3))
->create();
Post::factory()
->for(User::factory())
->create();التسلسلات
User::factory()
->count(3)
->sequence(
['role' => 'admin'],
['role' => 'user'],
['role' => 'guest'],
)->create();الاستدعاءات
public function configure()
{
return $this->afterCreating(function (User $user) {
$user->profile()->create();
});
}