2023-12-15 15:53:55 +00:00
|
|
|
<?php
|
|
|
|
|
|
2023-12-18 12:42:06 +01:00
|
|
|
namespace Database\Seeders\Development;
|
2023-12-15 15:53:55 +00:00
|
|
|
|
|
|
|
|
use App\Lib\Helpers\FileStorageHelper;
|
|
|
|
|
use App\Models\Game;
|
|
|
|
|
use Illuminate\Database\Seeder;
|
2023-12-18 12:42:06 +01:00
|
|
|
use Illuminate\Support\Facades\DB;
|
2023-12-18 11:33:22 +01:00
|
|
|
use Illuminate\Support\Facades\File;
|
2023-12-15 15:53:55 +00:00
|
|
|
|
|
|
|
|
class GameSeeder extends Seeder
|
|
|
|
|
{
|
|
|
|
|
/**
|
|
|
|
|
* Run the database seeds.
|
|
|
|
|
*
|
|
|
|
|
* @return void
|
|
|
|
|
*/
|
|
|
|
|
public function run()
|
|
|
|
|
{
|
2023-12-18 12:42:06 +01:00
|
|
|
DB::table((new Game())->getTable())->truncate();
|
2023-12-18 11:33:22 +01:00
|
|
|
File::deleteDirectory(\storage_path('app/public/modelfiles/' . (new Game())->getTable()));
|
2023-12-15 15:53:55 +00:00
|
|
|
|
|
|
|
|
$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();
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|