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/CategorySeeder.php

60 lines
1.4 KiB
PHTML

7 months ago
<?php
namespace Database\Seeders;
use App\Models\Category;
7 months ago
use Illuminate\Database\Console\Seeds\WithoutModelEvents;
use Illuminate\Database\Seeder;
class CategorySeeder extends Seeder
{
/**
* Run the database seeds.
*/
public function run(): void
{
//
$mainCategories = [
__("Mobile"),
__("Tablet"),
__("Desktop"),
__("Brands"),
];
$subCats = [
1 => [
__("Smart phone"),
__("Basic phones"),
],
3 => [
__("PC"),
__("Laptop"),
],
4 => [
__("Apple"),
__("HP (Hewlett-Packard)"),
__("Nokia"),
__("Samsung"),
__("Sony"),
],
];
// insert main categories
foreach ($mainCategories as $category){
$c = new Category();
$c->name = $category;
$c->slug = sluger($category);
$c->save();
}
foreach ($subCats as $k => $categories){
foreach ($categories as $category){
$c = new Category();
$c->name = $category;
$c->slug = sluger($category);
$c->parent_id = $k ;
$c->save();
}
}
7 months ago
}
}