Files
monica/app/Models/GiftOccasion.php
T

59 lines
1.4 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 GiftOccasion extends Model
{
use HasFactory;
protected $table = 'gift_occasions';
/**
* The attributes that are mass assignable.
*
* @var list<string>
*/
protected $fillable = [
'account_id',
'label',
'label_translation_key',
'position',
];
/**
* Get the account associated with the gift occasion.
*
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo<\App\Models\Account, $this>
*/
public function account(): BelongsTo
{
return $this->belongsTo(Account::class);
}
/**
* Get the name of the reverse relationship attribute.
* Gift occasion entries have a default name that can be translated.
* Howerer, if a name is set, it will be used instead of the default.
*
* @return Attribute<string,string>
*/
protected function label(): Attribute
{
return Attribute::make(
get: function ($value, $attributes) {
if (! $value) {
return __($attributes['label_translation_key']);
}
return $value;
},
set: fn ($value) => $value,
);
}
}