generated from liutk/owl-admin-base
38 lines
870 B
PHP
38 lines
870 B
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\MorphOne;
|
|
|
|
class PlanHygiene extends Model
|
|
{
|
|
use HasFactory;
|
|
|
|
protected $fillable = [
|
|
'month',
|
|
'store_ids',
|
|
];
|
|
|
|
public function plan(): MorphOne
|
|
{
|
|
return $this->morphOne(Plan::class, 'planable');
|
|
}
|
|
|
|
protected function storeIds(): 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 : []),
|
|
);
|
|
}
|
|
}
|