First Commit
This commit is contained in:
+74
@@ -0,0 +1,74 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* SysCMS - Content Management System
|
||||
*
|
||||
* Copyright (c) 2026 Marco Costa
|
||||
* All rights reserved.
|
||||
*
|
||||
* Author: Marco Costa
|
||||
* Email: contato@syspanel.com.br
|
||||
* Project: SysCMS
|
||||
*
|
||||
* This software is licensed, not sold.
|
||||
* Permission is granted to use this software
|
||||
* subject to the terms of the SysCMS Commercial License.
|
||||
*
|
||||
* Redistribution, sublicensing, resale, or
|
||||
* disclosure of this software, in whole or in part,
|
||||
* is strictly prohibited without prior written permission.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND.
|
||||
*/
|
||||
|
||||
namespace Modules\GlobalLists\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
/**
|
||||
* Class Country
|
||||
*
|
||||
* Model representing a country with multi-language name support.
|
||||
*
|
||||
* @package Modules\GlobalLists\Models
|
||||
* @property int $countries_id
|
||||
* @property array $countries_name JSON array of names in different locales
|
||||
* @property string $countries_iso_code ISO country code
|
||||
*/
|
||||
class Country extends Model
|
||||
{
|
||||
protected $table = 'lists_countries';
|
||||
protected $primaryKey = 'countries_id';
|
||||
|
||||
protected $fillable = [
|
||||
'countries_name',
|
||||
'countries_iso_code'
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'countries_name' => 'array'
|
||||
];
|
||||
|
||||
/**
|
||||
* Get the translated name.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getNameAttribute()
|
||||
{
|
||||
$names = $this->countries_name;
|
||||
if (is_array($names)) {
|
||||
$locale = \Kernel\Translator::getLocale() ?: 'pt_BR';
|
||||
return $names[$locale] ?? $names['pt_BR'] ?? array_shift($names);
|
||||
}
|
||||
return $names;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the states for the country.
|
||||
*/
|
||||
public function states()
|
||||
{
|
||||
return $this->hasMany(State::class, 'states_country_id', 'countries_id');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user