55 lines
1.7 KiB
PHP
55 lines
1.7 KiB
PHP
<?php
|
|
|
|
namespace Database\Seeders\Development;
|
|
|
|
use App\Lib\Helpers\FileStorageHelper;
|
|
use App\Models\Brand;
|
|
use App\Models\Font;
|
|
use App\Models\Range;
|
|
use Illuminate\Database\Seeder;
|
|
use Illuminate\Support\Facades\DB;
|
|
use Illuminate\Support\Facades\File;
|
|
use Illuminate\Support\Facades\Schema;
|
|
|
|
class RangeSeeder extends Seeder
|
|
{
|
|
/**
|
|
* Run the database seeds.
|
|
*
|
|
* @return void
|
|
*/
|
|
public function run(): void
|
|
{
|
|
Schema::disableForeignKeyConstraints();
|
|
DB::table((new Range())->getTable())->truncate();
|
|
Schema::enableForeignKeyConstraints();
|
|
File::deleteDirectory(\storage_path('app/public/modelfiles/' . (new Range())->getTable()));
|
|
|
|
$fonts = Font::all();
|
|
|
|
Brand::all()->each(
|
|
fn (Brand $brand) =>
|
|
Range::factory(\random_int(6, 16))->make()->each(function (Range $range) use ($brand, $fonts) {
|
|
if ($range->width === 1) {
|
|
$range->picture = FileStorageHelper::storeFile(
|
|
new Range(),
|
|
new \SplFileInfo(
|
|
\resource_path('../database/factories/assets/ranges/default-picture-600x500.jpg')
|
|
)
|
|
);
|
|
} else {
|
|
$range->picture = FileStorageHelper::storeFile(
|
|
new Range(),
|
|
new \SplFileInfo(
|
|
\resource_path('../database/factories/assets/ranges/default-picture-1300x500.jpg')
|
|
)
|
|
);
|
|
}
|
|
|
|
$range->brand()->associate($brand);
|
|
$range->font()->associate($fonts->random(1)->first());
|
|
$range->save();
|
|
})
|
|
);
|
|
}
|
|
}
|