ldc-tregalette/database/seeders/RangeSeeder.php
Jérémy Munsch e17023f61f
Fix Seeders
2023-12-18 11:33:22 +01:00

53 lines
1.7 KiB
PHP

<?php
namespace Database\Seeders;
use App\Lib\Helpers\FileStorageHelper;
use App\Models\Range;
use Illuminate\Database\Seeder;
use Illuminate\Support\Facades\File;
class RangeSeeder extends Seeder
{
/**
* Run the database seeds.
*
* @return void
*/
public function run()
{
File::deleteDirectory(\storage_path('app/public/modelfiles/' . (new Range())->getTable()));
Range::factory(3)->make()->each(function (Range $range) {
$range->picture = FileStorageHelper::storeFile(
new Range(),
new \SplFileInfo(
\resource_path('../database/factories/assets/ranges/default-picture-579x579.png')
)
);
$range->picture_ambiance = FileStorageHelper::storeFile(
new Range(),
new \SplFileInfo(
\resource_path('../database/factories/assets/ranges/default-picture-333x333.png')
)
);
if ($first = fake()->boolean(75)) {
$range->picto1_picture = FileStorageHelper::storeFile(
new Range(),
new \SplFileInfo(
\resource_path('../database/factories/assets/ranges/default-picture-67x70.png')
)
);
}
if ($first && fake()->boolean(75)) {
$range->picto2_picture = FileStorageHelper::storeFile(
new Range(),
new \SplFileInfo(
\resource_path('../database/factories/assets/ranges/default-picture-67x70.png')
)
);
}
$range->saveQuietly();
});
}
}