How to install
- Clone the repository with
git clone - Copy the
.env.examplefile to.envand edit database credentials there - Run
composer install - Run
php artisan key:generate - Run
php artisan storage:link - Run
php artisan migrate --seed(it has some seeded data for your testing) - Run
npm ciandnpm run build - Run
php artisan reverb:start - Launch the main URL
/. - Launch the URL
/admin. Log in with credentials[email protected]andpasswordto manage games. - That's it.
How It Works
Managing Games in Filament
The admin panel uses a custom Filament page for managing today's games in real-time. The page allows incrementing/decrementing scores and updating the game period.
app/Filament/Pages/ManageTodayGames.php:
public function incrementScore(int $gameId, string $team): void{ $game = Game::find($gameId); if ($team === 'home') { $game->increment('home_score'); } else { $game->increment('away_score'); } event(new GameUpdated($game->fresh())); $this->loadGames(); Notification::make() ->success() ->title('Score updated') ->body("Score updated to {$game->home_score} - {$game->away_score}") ->send();}
After updating the score, the GameUpdated event is fired with a fresh copy of the game. Using fresh() is important here because it retrieves the latest data from the database, ensuring that the event broadcasts the updated scores rather than stale data.
The same pattern is used for decrementing scores and updating the game period:
public function updatedPeriods($value, $gameId): void{ Game::where('id', $gameId)->update(['current_period' => GamePeriod::from($value)]); event(new GameUpdated(Game::find($gameId))); $this->loadGames();}