Created
March 14, 2020 12:02
-
-
Save palypster/89d38eeabddaf206d2f3cf4f1142aadd to your computer and use it in GitHub Desktop.
Cascading Laravel Factories - Cascading Factory
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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