59 lines
2 KiB
PHP
59 lines
2 KiB
PHP
<?php
|
|
|
|
namespace Database\Seeders\Mandatory;
|
|
|
|
use App\Lib\Helpers\FileStorageHelper;
|
|
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()
|
|
{
|
|
Schema::disableForeignKeyConstraints();
|
|
DB::table((new Range())->getTable())->truncate();
|
|
Schema::enableForeignKeyConstraints();
|
|
|
|
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();
|
|
});
|
|
}
|
|
}
|