generated from liutk/owl-admin-base
54 lines
1.3 KiB
PHP
54 lines
1.3 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use App\Traits\HasCheckable;
|
|
use App\Traits\HasDateTimeFormatter;
|
|
use Illuminate\Database\Eloquent\Casts\Attribute;
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|
use Illuminate\Database\Eloquent\Relations\MorphOne;
|
|
|
|
class TaskHygiene extends Model
|
|
{
|
|
use HasCheckable, HasFactory, HasDateTimeFormatter;
|
|
|
|
protected $fillable = [
|
|
'month',
|
|
'store_id',
|
|
'store_master_id',
|
|
'description',
|
|
'photos',
|
|
];
|
|
|
|
public function task(): MorphOne
|
|
{
|
|
return $this->morphOne(Task::class, 'taskable');
|
|
}
|
|
|
|
public function store(): BelongsTo
|
|
{
|
|
return $this->belongsTo(Store::class);
|
|
}
|
|
|
|
public function storeMaster(): BelongsTo
|
|
{
|
|
return $this->belongsTo(Employee::class, 'store_master_id');
|
|
}
|
|
|
|
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 : []),
|
|
);
|
|
}
|
|
}
|