Skip to content
This repository has been archived by the owner on Sep 12, 2022. It is now read-only.

Commit

Permalink
Updated Projects table seeder
Browse files Browse the repository at this point in the history
  • Loading branch information
FaZeRs committed May 4, 2019
1 parent 28472b0 commit d767557
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
6 changes: 4 additions & 2 deletions database/factories/ProjectFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,12 @@
|
*/
$factory->define(App\Models\Project::class, function (Faker $faker) {
$category = App\Models\Category::inRandomOrder()->first();

return [
'title' => $faker->sentence,
'category_id' => function () {
return factory(App\Models\Category::class)->create()->id;
'category_id' => function () use ($category) {
return optional($category)->id ?? factory(App\Models\Category::class)->create()->id;
},
'description' => $faker->paragraph,
'image' => 'projects/' . $faker->image(storage_path('app/public/projects'), 640, 480, null, false),
Expand Down
4 changes: 1 addition & 3 deletions database/seeds/ProjectsTableSeeder.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@ class ProjectsTableSeeder extends Seeder
*/
public function run()
{
factory(App\Models\Project::class, 6)->create([
'category_id' => App\Models\Category::inRandomOrder()->first()->id
])->each(function ($project) {
factory(App\Models\Project::class, 6)->create()->each(function ($project) {
$project->tags()->saveMany(App\Models\Tag::inRandomOrder()->take(3)->get());
$project->links()->saveMany(factory(App\Models\Link::class, 2)->make([
'project_id' => $project->id,
Expand Down

0 comments on commit d767557

Please sign in to comment.