57 lines
1.3 KiB
PHP
57 lines
1.3 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Casts\Attribute;
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|
|
|
class Religion extends Model
|
|
{
|
|
use HasFactory;
|
|
|
|
/**
|
|
* The attributes that are mass assignable.
|
|
*
|
|
* @var list<string>
|
|
*/
|
|
protected $fillable = [
|
|
'account_id',
|
|
'name',
|
|
'translation_key',
|
|
'position',
|
|
];
|
|
|
|
/**
|
|
* Get the account associated with the religion.
|
|
*
|
|
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo<\App\Models\Account, $this>
|
|
*/
|
|
public function account(): BelongsTo
|
|
{
|
|
return $this->belongsTo(Account::class);
|
|
}
|
|
|
|
/**
|
|
* Get the name of the religion.
|
|
* The name is either the default name that we get from the translation key,
|
|
* or the name that the user has entered.
|
|
*
|
|
* @return Attribute<string,string>
|
|
*/
|
|
protected function name(): Attribute
|
|
{
|
|
return Attribute::make(
|
|
get: function ($value, $attributes) {
|
|
if (is_null($attributes['name'])) {
|
|
return __($attributes['translation_key']);
|
|
}
|
|
|
|
return $attributes['name'];
|
|
},
|
|
set: fn ($value) => $value,
|
|
);
|
|
}
|
|
}
|