generated from liutk/owl-admin-base
48 lines
1.1 KiB
PHP
48 lines
1.1 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use App\Traits\HasDateTimeFormatter;
|
|
use EloquentFilter\Filterable;
|
|
use Illuminate\Database\Eloquent\Casts\Attribute;
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|
|
|
class Reimbursement extends Model
|
|
{
|
|
use Filterable, HasDateTimeFormatter, HasFactory;
|
|
|
|
protected $fillable = [
|
|
'employee_id',
|
|
'reimbursement_type_id',
|
|
'expense',
|
|
'reason',
|
|
'photos',
|
|
];
|
|
|
|
public function employee(): BelongsTo
|
|
{
|
|
return $this->belongsTo(Employee::class);
|
|
}
|
|
|
|
public function type(): BelongsTo
|
|
{
|
|
return $this->belongsTo(Keyword::class, 'reimbursement_type_id', 'key');
|
|
}
|
|
|
|
protected function photos(): Attribute
|
|
{
|
|
return Attribute::make(
|
|
get: function (mixed $value) {
|
|
if (! is_array($photos = json_decode($value ?? '', true))) {
|
|
$photos = [];
|
|
}
|
|
|
|
return $photos;
|
|
},
|
|
set: fn (mixed $value) => json_encode(is_array($value) ? $value : []),
|
|
);
|
|
}
|
|
}
|