create image upload endpoint create product creation endpoint create get product categories endpoint
29 lines
708 B
PHP
29 lines
708 B
PHP
<?php
|
|
|
|
namespace Database\Seeders;
|
|
|
|
use App\Models\ProductCategory;
|
|
use Illuminate\Database\Seeder;
|
|
use Illuminate\Support\Str;
|
|
|
|
class ProductCategorySeeder extends Seeder
|
|
{
|
|
public function run(): void
|
|
{
|
|
$names = [
|
|
'Electronics', 'Clothing', 'Home', 'Books',
|
|
'Sports', 'Toys', 'Health', 'Beauty', 'Automotive',
|
|
];
|
|
|
|
// Transform the flat names into an array of associative arrays
|
|
$categories = collect($names)->map(function ($name) {
|
|
return [
|
|
'name' => $name,
|
|
'slug' => Str::slug($name),
|
|
];
|
|
})->toArray();
|
|
|
|
ProductCategory::upsert($categories, ['name'], ['slug']);
|
|
}
|
|
}
|