Skip to content

Commit ae9d6fc

Browse files
committed
chore(regions): allow setting special regions with start and optional end dates
1 parent 179d374 commit ae9d6fc

8 files changed

Lines changed: 73 additions & 29 deletions

File tree

database/migrations/2025_07_29_161719_add_default_to_start_date.php

Lines changed: 0 additions & 23 deletions
This file was deleted.

resources/lang/en/countries.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,10 @@
8080
'special_regions' => [
8181
'label' => 'Special Regions',
8282
'helper' => 'Special regions this country belongs to (e.g., European Union)',
83+
'add_button' => 'Add Special Region',
84+
'region_label' => 'Region',
85+
'start_date_label' => 'Start Date',
86+
'end_date_label' => 'End Date',
8387
],
8488
],
8589

resources/lang/hr/countries.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,10 @@
8080
'special_regions' => [
8181
'label' => 'Posebne regije',
8282
'helper' => 'Posebne regije kojima ova zemlja pripada (npr. Europska unija)',
83+
'add_button' => 'Dodaj posebnu regiju',
84+
'region_label' => 'Regija',
85+
'start_date_label' => 'Datum početka',
86+
'end_date_label' => 'Datum završetka',
8387
],
8488
],
8589

resources/lang/sl/countries.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,10 @@
8080
'special_regions' => [
8181
'label' => 'Posebne regije',
8282
'helper' => 'Posebne regije, ki jim ta država pripada (npr. Evropska unija)',
83+
'add_button' => 'Dodaj posebno regijo',
84+
'region_label' => 'Regija',
85+
'start_date_label' => 'Datum začetka',
86+
'end_date_label' => 'Datum konca',
8387
],
8488
],
8589

resources/lang/sr/countries.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,10 @@
8080
'special_regions' => [
8181
'label' => 'Posebne regije',
8282
'helper' => 'Posebne regije kojima ova zemlja pripada (npr. Evropska unija)',
83+
'add_button' => 'Dodaj posebnu regiju',
84+
'region_label' => 'Regija',
85+
'start_date_label' => 'Datum početka',
86+
'end_date_label' => 'Datum završetka',
8387
],
8488
],
8589

src/Filament/Clusters/World/Resources/CountryResource.php

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
use Eclipse\World\Filament\Clusters\World;
77
use Eclipse\World\Filament\Clusters\World\Resources\CountryResource\Pages;
88
use Eclipse\World\Models\Country;
9+
use Filament\Forms\Components\DatePicker;
10+
use Filament\Forms\Components\Repeater;
911
use Filament\Forms\Components\Select;
1012
use Filament\Forms\Components\TextInput;
1113
use Filament\Forms\Form;
@@ -80,13 +82,29 @@ public static function form(Form $form): Form
8082
->preload()
8183
->helperText(__('eclipse-world::countries.form.region.helper')),
8284

83-
Select::make('special_regions')
85+
Repeater::make('countryInSpecialRegions')
86+
->relationship()
8487
->label(__('eclipse-world::countries.form.special_regions.label'))
85-
->multiple()
86-
->relationship('specialRegions', 'name', fn ($query) => $query->where('is_special', true))
87-
->searchable()
88-
->preload()
89-
->helperText(__('eclipse-world::countries.form.special_regions.helper')),
88+
->columns(3)
89+
->columnSpan(2)
90+
->createItemButtonLabel(__('eclipse-world::countries.form.special_regions.add_button'))
91+
->defaultItems(0)
92+
->minItems(0)
93+
->schema([
94+
Select::make('region_id')
95+
->relationship('region', 'name', fn ($query) => $query->where('is_special', true))
96+
->searchable()
97+
->preload()
98+
->label(__('eclipse-world::countries.form.special_regions.region_label')),
99+
100+
DatePicker::make('start_date')
101+
->required()
102+
->label(__('eclipse-world::countries.form.special_regions.start_date_label')),
103+
104+
DatePicker::make('end_date')
105+
->nullable()
106+
->label(__('eclipse-world::countries.form.special_regions.end_date_label')),
107+
]),
90108
]);
91109
}
92110

src/Models/Country.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use Illuminate\Database\Eloquent\Model;
99
use Illuminate\Database\Eloquent\Relations\BelongsTo;
1010
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
11+
use Illuminate\Database\Eloquent\Relations\HasMany;
1112
use Illuminate\Database\Eloquent\SoftDeletes;
1213
use Illuminate\Support\Carbon;
1314

@@ -48,6 +49,11 @@ public function specialRegions(): BelongsToMany
4849
->withTimestamps();
4950
}
5051

52+
public function countryInSpecialRegions(): HasMany
53+
{
54+
return $this->hasMany(CountryInSpecialRegion::class, 'country_id');
55+
}
56+
5157
/**
5258
* Check if the country belongs to a special region at a given date.
5359
*/
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
3+
namespace Eclipse\World\Models;
4+
5+
use Illuminate\Database\Eloquent\Relations\Pivot;
6+
7+
class CountryInSpecialRegion extends Pivot
8+
{
9+
protected $table = 'world_country_in_special_region';
10+
11+
protected $casts = [
12+
'start_date' => 'date',
13+
'end_date' => 'date',
14+
];
15+
16+
protected $fillable = [
17+
'country_id',
18+
'region_id',
19+
'start_date',
20+
'end_date',
21+
];
22+
23+
public function region()
24+
{
25+
return $this->belongsTo(Region::class);
26+
}
27+
}

0 commit comments

Comments
 (0)