Skip to content

Instantly share code, notes, and snippets.

@palypster
Created March 14, 2020 12:02
Show Gist options
  • Save palypster/89d38eeabddaf206d2f3cf4f1142aadd to your computer and use it in GitHub Desktop.
Save palypster/89d38eeabddaf206d2f3cf4f1142aadd to your computer and use it in GitHub Desktop.
Cascading Laravel Factories - Cascading Factory
<?php
/** @var \Illuminate\Database\Eloquent\Factory $factory */
use App\Client;
use App\Project;
use Faker\Generator as Faker;
$factory->define(Project::class, function (Faker $faker) {
return [
'title' => $faker->sentence,
// cascade all dependent relations
'client_id' => factory(Client::class)->create()->getKey()
];
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment