43 lines
966 B
PHP
43 lines
966 B
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use App\Enums\Page;
|
|
use App\Lib\Utils;
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Kwaadpepper\Enum\Traits\CastsEnums;
|
|
|
|
class Moment extends Model
|
|
{
|
|
use HasFactory;
|
|
use CastsEnums;
|
|
|
|
public $enumCasts = [
|
|
'page' => Page::class
|
|
];
|
|
|
|
protected $fillable = [
|
|
'title',
|
|
'subtitle',
|
|
'text',
|
|
'picture'
|
|
'alt_text_picture',
|
|
];
|
|
|
|
protected static function boot()
|
|
{
|
|
static::creating(function (Moment $moment) {
|
|
if ($moment->picture) {
|
|
$moment->picture = Utils::storeImage($moment->picture, $moment->getTable());
|
|
}
|
|
});
|
|
|
|
static::updating(function (Moment $moment) {
|
|
if ($moment->picture) {
|
|
$moment->picture = Utils::storeImage($moment->picture, $moment->getTable());
|
|
}
|
|
});
|
|
parent::boot();
|
|
}
|
|
}
|