davide-casiraghi /
laravel-events-calendar
| 1 | <?php |
||
| 2 | |||
| 3 | namespace DavideCasiraghi\LaravelEventsCalendar\Models; |
||
| 4 | |||
| 5 | use Astrotomic\Translatable\Translatable; |
||
| 6 | use Illuminate\Database\Eloquent\Model; |
||
| 7 | |||
| 8 | class Region extends Model |
||
| 9 | { |
||
| 10 | /***************************************************************************/ |
||
| 11 | /** |
||
| 12 | * The table associated with the model. |
||
| 13 | * |
||
| 14 | * @var string |
||
| 15 | */ |
||
| 16 | protected $table = 'regions'; |
||
| 17 | |||
| 18 | /***************************************************************************/ |
||
| 19 | |||
| 20 | use Translatable; |
||
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||
| 21 | |||
| 22 | public $translatedAttributes = ['name', 'slug']; |
||
| 23 | protected $fillable = ['country_id', 'timezone']; |
||
| 24 | public $useTranslationFallback = true; |
||
| 25 | |||
| 26 | /***************************************************************************/ |
||
| 27 | |||
| 28 | /* |
||
| 29 | * Return the region name. |
||
| 30 | * |
||
| 31 | * @param int $regionId |
||
| 32 | * @return string |
||
| 33 | */ |
||
| 34 | 1 | public static function getRegionName($regionId): string |
|
| 35 | { |
||
| 36 | 1 | $ret = self::find($regionId)->name; |
|
|
0 ignored issues
–
show
|
|||
| 37 | |||
| 38 | 1 | return $ret; |
|
| 39 | } |
||
| 40 | |||
| 41 | /***************************************************************************/ |
||
| 42 | |||
| 43 | /** |
||
| 44 | * Return all the countries ordered by name. |
||
| 45 | * |
||
| 46 | * @return \Illuminate\Support\Collection |
||
| 47 | */ |
||
| 48 | 1 | public static function getRegionsByCountry($countryId) |
|
| 49 | { |
||
| 50 | 1 | $ret = self::join('region_translations', 'regions.id', '=', 'region_translations.region_id') |
|
| 51 | 1 | ->where('locale', 'en') |
|
| 52 | 1 | ->where('country_id', $countryId) |
|
| 53 | 1 | ->orderBy('name') |
|
| 54 | 1 | ->pluck('name', 'region_translations.region_id AS id'); |
|
| 55 | |||
| 56 | 1 | return $ret; |
|
| 57 | } |
||
| 58 | } |
||
| 59 |