Skip to content

Instantly share code, notes, and snippets.

@palypster
Last active March 14, 2020 22:31
Show Gist options
  • Save palypster/9ebe56db8d4172651b5ce197f895a1a5 to your computer and use it in GitHub Desktop.
Save palypster/9ebe56db8d4172651b5ce197f895a1a5 to your computer and use it in GitHub Desktop.
<?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