You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
xshop/database/seeders/ProductSeeder.php

26 lines
557 B
PHTML

7 months ago
<?php
namespace Database\Seeders;
use App\Models\Category;
use App\Models\Product;
7 months ago
use Illuminate\Database\Console\Seeds\WithoutModelEvents;
use Illuminate\Database\Seeder;
class ProductSeeder extends Seeder
{
/**
* Run the database seeds.
*/
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();
}
7 months ago
}
}