41 lines
853 B
PHP
Executable File
41 lines
853 B
PHP
Executable File
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\Relations\MorphTo;
|
|
use Illuminate\Database\Eloquent\Relations\MorphMany;
|
|
|
|
class Articles extends Model
|
|
{
|
|
protected $guarded = [];
|
|
|
|
protected function casts(): array
|
|
{
|
|
return [
|
|
'aOpt' => 'array',
|
|
'aSchemaPro' => 'array',
|
|
];
|
|
}
|
|
|
|
protected static function booted(): void
|
|
{
|
|
static::deleting(function ($oArticle) {
|
|
$oArticle->oImages()->get()->each(function ($oImage) {
|
|
$oImage->delete();
|
|
});
|
|
});
|
|
}
|
|
|
|
public function oSubject(): MorphTo
|
|
{
|
|
return $this->morphTo('oSubject');
|
|
}
|
|
|
|
public function oImages(): MorphMany
|
|
{
|
|
return $this->morphMany(UploadImages::class, 'oImageable');
|
|
}
|
|
|
|
}
|