47 lines
1.5 KiB
PHP
47 lines
1.5 KiB
PHP
<?php
|
|
|
|
namespace Database\Seeders;
|
|
|
|
use App\Models\Answer;
|
|
use App\Models\Brand;
|
|
use App\Models\Question;
|
|
use App\Models\Service;
|
|
use Illuminate\Database\Seeder;
|
|
use Uwil\LaravelCommon\Helpers\FileHelper;
|
|
|
|
class BrandSeeder extends Seeder
|
|
{
|
|
/**
|
|
* Run the database seeds.
|
|
*
|
|
* @return void
|
|
*/
|
|
public function run(): void
|
|
{
|
|
/** @var \App\Models\Brand $brand */
|
|
Brand::factory(10)->make()->each(function ($brand) {
|
|
$brand->logo = FileHelper::storeFile(
|
|
$brand,
|
|
new \SplFileInfo(
|
|
\resource_path('../database/factories/assets/brands/default-logo-550x550.jpg')
|
|
)
|
|
);
|
|
$brand->saveOrFail();
|
|
Service::factory(1)->make()->each(
|
|
/** @var \App\Models\Service $service*/
|
|
function ($service) use ($brand) {
|
|
Question::factory(10)->make()->each(function ($question) use ($brand) {
|
|
$question->brand()->associate($brand);
|
|
$question->save();
|
|
Answer::factory(rand(3, 4))->make()->each(function ($answer) use ($question) {
|
|
$answer->question()->associate($question);
|
|
$answer->save();
|
|
});
|
|
});
|
|
$service->brand()->associate($brand);
|
|
$service->save();
|
|
}
|
|
);
|
|
});
|
|
}
|
|
}
|