Last active
March 14, 2020 22:31
-
-
Save palypster/9ebe56db8d4172651b5ce197f895a1a5 to your computer and use it in GitHub Desktop.
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 \App\ExtendedFactory $factory */ | |
use App\User; | |
use App\Category; | |
use App\Project; | |
use Faker\Generator as Faker; | |
$factory->define(Task::class, function (Faker $faker) { | |
return [ | |
// | |
]; | |
}); | |
$factory->cascadeState(Task::class, 'project', | |
function (Task $task, $faker) { | |
$task->project_id = factory(Project::class)->cascade()->create()->getKey(); | |
} | |
); | |
$factory->cascadeState(Task::class, 'assignee', | |
function (Task $task, $faker) { | |
$task->assignee_id = factory(User::class)->cascade()->create()->getKey(); | |
} | |
); | |
$factory->cascadeState(Task::class, 'taskCategory', | |
function (Task $task, $faker) { | |
$task->category_id = factory(Category::class)->cascade()->create()->getKey(); | |
} | |
); | |
$factory->reuseState(Task::class, 'project', | |
function (Task $task, $faker) { | |
$task->project_id = Project::::query()->inRandomOrder()->first()->getKey(); | |
} | |
); | |
$factory->reuseState(Task::class, 'assignee', | |
function (Task $task, $faker) { | |
$task->assignee_id = User::::query()->inRandomOrder()->first()->getKey(); | |
} | |
); | |
$factory->reuseState(Task::class, 'taskCategory', | |
function (Task $task, $faker) { | |
$task->category_id = Category::query()->inRandomOrder()->first()->getKey() | |
} | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment