2024-01-05 14:54:08 +01:00
|
|
|
<?php
|
|
|
|
|
|
2024-01-05 17:36:16 +01:00
|
|
|
namespace Database\Seeders\Development;
|
2024-01-05 14:54:08 +01:00
|
|
|
|
|
|
|
|
use App\Models\Brand;
|
2024-01-15 15:39:09 +01:00
|
|
|
use App\Models\Font;
|
2024-01-05 14:54:08 +01:00
|
|
|
use App\Models\Range;
|
|
|
|
|
use Illuminate\Database\Seeder;
|
|
|
|
|
use Illuminate\Support\Facades\DB;
|
|
|
|
|
use Illuminate\Support\Facades\File;
|
|
|
|
|
use Illuminate\Support\Facades\Schema;
|
2025-05-27 09:11:43 +02:00
|
|
|
use Uwil\LaravelCommon\Helpers\FileHelper;
|
2024-01-05 14:54:08 +01:00
|
|
|
|
|
|
|
|
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()));
|
|
|
|
|
|
2024-01-15 15:39:09 +01:00
|
|
|
$fonts = Font::all();
|
2024-01-05 14:54:08 +01:00
|
|
|
|
|
|
|
|
Brand::all()->each(
|
2025-05-27 09:11:43 +02:00
|
|
|
fn(Brand $brand) =>
|
2024-01-15 15:39:09 +01:00
|
|
|
Range::factory(\random_int(6, 16))->make()->each(function (Range $range) use ($brand, $fonts) {
|
2024-01-15 16:32:49 +01:00
|
|
|
if ($range->width === 1) {
|
2025-05-27 09:11:43 +02:00
|
|
|
$range->picture = FileHelper::storeFile(
|
2024-01-15 16:32:49 +01:00
|
|
|
new Range(),
|
|
|
|
|
new \SplFileInfo(
|
|
|
|
|
\resource_path('../database/factories/assets/ranges/default-picture-600x500.jpg')
|
2025-05-27 09:11:43 +02:00
|
|
|
),
|
|
|
|
|
prefix: $range->tenant_id
|
2024-01-15 16:32:49 +01:00
|
|
|
);
|
|
|
|
|
} else {
|
2025-05-27 09:11:43 +02:00
|
|
|
$range->picture = FileHelper::storeFile(
|
2024-01-15 16:32:49 +01:00
|
|
|
new Range(),
|
|
|
|
|
new \SplFileInfo(
|
|
|
|
|
\resource_path('../database/factories/assets/ranges/default-picture-1300x500.jpg')
|
2025-05-27 09:11:43 +02:00
|
|
|
),
|
|
|
|
|
prefix: $range->tenant_id
|
2024-01-15 16:32:49 +01:00
|
|
|
);
|
|
|
|
|
}
|
2024-01-15 15:39:09 +01:00
|
|
|
|
2024-01-05 14:54:08 +01:00
|
|
|
$range->brand()->associate($brand);
|
2024-01-15 15:39:09 +01:00
|
|
|
$range->font()->associate($fonts->random(1)->first());
|
2024-01-05 14:54:08 +01:00
|
|
|
$range->save();
|
|
|
|
|
})
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|