ldc-gen-game-web/app/Http/Middleware/CheckGameStatus.php

38 lines
1.2 KiB
PHP

<?php
namespace App\Http\Middleware;
use App\Models\Settings;
use Illuminate\Http\Request;
class CheckGameStatus
{
/**
* Handle an incoming request.
*
* * Check with game settings which page should be shown and redirect if needed.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return mixed
* @throws \RuntimeException If tha game has an unhandled state.
*/
public function handle(Request $request, \Closure $next)
{
/** @var \App\Models\Settings $settings */
$settings = app(Settings::class);
return match (true) {
// * End page
$settings->should_display_end_page => redirect()->route('fo.end'),
// * Teaser
$settings->should_display_teaser_page => redirect()->route('fo.teaser'),
// * Game is ended
$settings->game_has_ended => redirect($settings->redirect_close),
// * Game has started
$settings->game_has_begun => $next($request),
// * The game will begun, but has no teaser activated.
default => redirect($settings->redirect_close)
};
}
}