Skip to content

Commit

Permalink
improved product seeder
Browse files Browse the repository at this point in the history
  • Loading branch information
A1Gard committed Oct 2, 2024
1 parent 316452d commit a75eda9
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions database/seeders/ProductSeeder.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Database\Seeders;

use App\Models\Category;
use App\Models\Product;
use Illuminate\Database\Console\Seeds\WithoutModelEvents;
use Illuminate\Database\Seeder;
Expand All @@ -15,5 +16,10 @@ public function run(): void
{
//
Product::factory()->count(31)->create();

foreach (Product::all() as $product) {
$product->categories()->sync(Category::inRandomOrder()->limit(3)->pluck('id')->toArray());
$product->save();
}
}
}

0 comments on commit a75eda9

Please sign in to comment.