improved product seeder

pull/49/head
A1Gard 2 months ago
parent 316452d7b7
commit a75eda97e4

@ -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;
@ -15,5 +16,10 @@ class ProductSeeder extends Seeder
{
//
Product::factory()->count(31)->create();
foreach (Product::all() as $product) {
$product->categories()->sync(Category::inRandomOrder()->limit(3)->pluck('id')->toArray());
$product->save();
}
}
}

Loading…
Cancel
Save