From a27b5bfc65c639eeb13750798beedb2c459a7bfd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andrei=20Ioni=C8=9B=C4=83?= Date: Thu, 21 Nov 2024 17:48:26 +0200 Subject: [PATCH] wip --- app/Http/Controllers/RedirectToElectionController.php | 9 ++++++++- app/Models/Election.php | 2 ++ app/View/Components/Timeline.php | 1 + .../0001_01_02_000001_create_election_tables.php | 3 ++- 4 files changed, 13 insertions(+), 2 deletions(-) diff --git a/app/Http/Controllers/RedirectToElectionController.php b/app/Http/Controllers/RedirectToElectionController.php index dea018a..98c60dd 100644 --- a/app/Http/Controllers/RedirectToElectionController.php +++ b/app/Http/Controllers/RedirectToElectionController.php @@ -11,7 +11,14 @@ class RedirectToElectionController extends Controller { public function __invoke(?Election $election = null): RedirectResponse { - $election ??= Election::latest()->first(); + $election ??= Election::query() + ->where('is_visible', true) + ->latest() + ->first(); + + if (blank($election)) { + abort(404); + } return redirect()->to($election->getDefaultUrl()); } diff --git a/app/Models/Election.php b/app/Models/Election.php index 62a2909..26ba847 100644 --- a/app/Models/Election.php +++ b/app/Models/Election.php @@ -29,6 +29,7 @@ class Election extends Model implements HasName, HasAvatar 'subtitle', 'slug', 'date', + 'is_visible', 'is_live', 'has_lists', 'properties', @@ -41,6 +42,7 @@ protected function casts(): array 'type' => ElectionType::class, 'date' => 'date', 'year' => 'int', + 'is_visible' => 'boolean', 'is_live' => 'boolean', 'has_lists' => 'boolean', 'properties' => 'collection', diff --git a/app/View/Components/Timeline.php b/app/View/Components/Timeline.php index 148c3b9..ec186d4 100644 --- a/app/View/Components/Timeline.php +++ b/app/View/Components/Timeline.php @@ -21,6 +21,7 @@ class Timeline extends Component public function __construct() { $this->years = Election::query() + ->where('is_visible', true) ->get() ->groupBy([ 'year', diff --git a/database/migrations/0001_01_02_000001_create_election_tables.php b/database/migrations/0001_01_02_000001_create_election_tables.php index 8dd066d..217c131 100644 --- a/database/migrations/0001_01_02_000001_create_election_tables.php +++ b/database/migrations/0001_01_02_000001_create_election_tables.php @@ -18,7 +18,8 @@ public function up(): void $table->string('slug')->unique(); $table->date('date'); $table->year('year')->storedAs('(YEAR(date))'); - $table->boolean('is_live'); + $table->boolean('is_visible')->default(true); + $table->boolean('is_live')->default(false); $table->boolean('has_lists')->default(false); $table->json('properties')->nullable(); $table->timestamps();