ldc-tregalette/database/seeders/Development/GameSeeder.php
2023-12-18 12:42:06 +01:00

43 lines
1.4 KiB
PHP

<?php
namespace Database\Seeders\Development;
use App\Lib\Helpers\FileStorageHelper;
use App\Models\Game;
use Illuminate\Database\Seeder;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\File;
class GameSeeder extends Seeder
{
/**
* Run the database seeds.
*
* @return void
*/
public function run()
{
DB::table((new Game())->getTable())->truncate();
File::deleteDirectory(\storage_path('app/public/modelfiles/' . (new Game())->getTable()));
$publish_at = now()->addMonth();
$unpublish_at = $publish_at->copy()->addDays(rand(10, 20));
for ($i = 0; $i < 5; $i++) {
Game::factory(1)->make()->each(
function (Game $game) use ($i, $publish_at, $unpublish_at) {
$game->published = $i === 0 ? true : false;
$game->publish_at = $publish_at->subMonths();
$game->unpublish_at = $unpublish_at->subMonths();
$game->picture = FileStorageHelper::storeFile(
new Game(),
new \SplFileInfo(
\resource_path('../database/factories/assets/games/default-picture-585x415.png')
)
);
$game->saveQuietly();
}
);
}
}
}