generated from liutk/owl-admin-base
48 lines
1001 B
PHP
48 lines
1001 B
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use App\Enums\PlanStatus;
|
|
use App\Traits\HasDateTimeFormatter;
|
|
use EloquentFilter\Filterable;
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\Relations\MorphTo;
|
|
|
|
class Plan extends Model
|
|
{
|
|
use Filterable, HasDateTimeFormatter, HasFactory;
|
|
|
|
protected $attributes = [
|
|
'plan_status' => PlanStatus::Pending,
|
|
];
|
|
|
|
protected $casts = [
|
|
'plan_status' => PlanStatus::class,
|
|
];
|
|
|
|
protected $fillable = [
|
|
'name',
|
|
'plan_status',
|
|
'planable_id',
|
|
'planable_type',
|
|
];
|
|
|
|
protected static function booted(): void
|
|
{
|
|
static::deleting(function (Task $model) {
|
|
$model->planable()->delete();
|
|
});
|
|
}
|
|
|
|
public function planable(): MorphTo
|
|
{
|
|
return $this->morphTo();
|
|
}
|
|
|
|
public function isPublished(): bool
|
|
{
|
|
return $this->plan_status === PlanStatus::Published;
|
|
}
|
|
}
|