diff --git a/app/Enums/ElectionType.php b/app/Enums/ElectionType.php
index 0aba596..4106546 100644
--- a/app/Enums/ElectionType.php
+++ b/app/Enums/ElectionType.php
@@ -8,16 +8,16 @@
use App\Concerns\Enums\Comparable;
use Filament\Support\Contracts\HasLabel;
-enum ElectionType: string implements HasLabel
+enum ElectionType: int implements HasLabel
{
use Arrayable;
use Comparable;
- case PRESIDENTIAL = 'presidential';
- case PARLIAMENTARY = 'parliamentary';
- case EURO = 'euro';
- case LOCAL = 'local';
- case REFERENDUM = 'referendum';
+ case PRESIDENTIAL = 1;
+ case REFERENDUM = 2;
+ case PARLIAMENTARY = 3;
+ case LOCAL = 4;
+ case EURO = 5;
public function getLabel(): ?string
{
diff --git a/app/Models/Election.php b/app/Models/Election.php
index 3e7a302..7fd2d6b 100644
--- a/app/Models/Election.php
+++ b/app/Models/Election.php
@@ -58,7 +58,8 @@ protected static function booted(): void
static::addGlobalScope('latest', function (Builder $query) {
return $query
->orderByDesc('year')
- ->orderByDesc('is_live');
+ ->orderByDesc('is_live')
+ ->orderBy('type');
});
}
diff --git a/app/View/Components/Timeline.php b/app/View/Components/Timeline.php
index 128b631..ba09cb9 100644
--- a/app/View/Components/Timeline.php
+++ b/app/View/Components/Timeline.php
@@ -20,8 +20,7 @@ class Timeline extends Component
public function __construct()
{
- $this->years = Election::query()
- ->get()
+ $this->years = Election::all()
->groupBy([
'year',
fn (Election $election) => $election->type->getLabel(),
diff --git a/database/migrations/2024_11_23_234448_change_type_column_in_elections_table.php b/database/migrations/2024_11_23_234448_change_type_column_in_elections_table.php
new file mode 100644
index 0000000..5e256f0
--- /dev/null
+++ b/database/migrations/2024_11_23_234448_change_type_column_in_elections_table.php
@@ -0,0 +1,44 @@
+tinyInteger('new_type')->after('type');
+ });
+
+ $this->migrateData();
+
+ Schema::table('elections', function (Blueprint $table) {
+ $table->dropColumn('type');
+ $table->renameColumn('new_type', 'type');
+ });
+ }
+
+ protected function migrateData(): void
+ {
+ collect([
+ 'presidential' => ElectionType::PRESIDENTIAL,
+ 'referendum' => ElectionType::REFERENDUM,
+ 'parliamentary' => ElectionType::PARLIAMENTARY,
+ 'local' => ElectionType::LOCAL,
+ 'euro' => ElectionType::EURO,
+ ])->each(
+ fn (ElectionType $newType, string $oldType) => DB::table('elections')
+ ->where('type', $oldType)
+ ->update(['new_type' => $newType])
+ );
+ }
+};
diff --git a/resources/views/livewire/pages/election-turnouts.blade.php b/resources/views/livewire/pages/election-turnouts.blade.php
index 2384492..c1f7db9 100644
--- a/resources/views/livewire/pages/election-turnouts.blade.php
+++ b/resources/views/livewire/pages/election-turnouts.blade.php
@@ -1,3 +1,4 @@
+@use('App\Enums\ElectionType')
@use('App\Livewire\Charts')
@use('Filament\Support\Colors\Color')
@@ -66,7 +67,9 @@
:election="$election"
show-embed />
-
+ @if ($election->type->isNot(ElectionType::REFERENDUM))
+
+ @endif