Custom database seeder with bagisto faker

This commit is contained in:
merdan 2021-10-25 22:16:18 +05:00
parent 2f835ea6b2
commit be0d614b36
1 changed files with 0 additions and 52 deletions

View File

@ -1,52 +0,0 @@
<?php
namespace Sarga\Shop\Database\Seeders;
use Faker\Generator as Faker;
use Illuminate\Database\Seeder;
use Webkul\Category\Repositories\CategoryRepository;
class DemoCategoryTableSeeder extends Seeder
{
private $numberOfParentCategories = 10;
private $numberOfChildCategories = 5;
public function __construct(
Faker $faker,
CategoryRepository $categoryRepository
)
{
$this->faker = $faker;
$this->categoryRepository = $categoryRepository;
}
public function run()
{
$this->categoryRepository->deleteWhere([['id', '!=', 1]]);
for ($i = 2; $i < $this->numberOfParentCategories; $i++) {
$createdCategory = $this->categoryRepository->create([
'id' => $i,
'slug' => $this->faker->slug,
'name' => $this->faker->firstName,
'description' => $this->faker->text(),
'parent_id' => 1,
'status' => 1,
]);
if ($createdCategory) {
for ($j = ($i-1)*$this->numberOfParentCategories; $j < ($i-1)*$this->numberOfParentCategories+$this->numberOfChildCategories; ++$j) {
$this->categoryRepository->create([
'id' => $j,
'slug' => $this->faker->slug,
'name' => $this->faker->firstName,
'description' => $this->faker->text(),
'parent_id' => $createdCategory->id,
'status' => 1
]);
}
}
}
}
}