ldc-doux/app/Models/Encart.php
2021-12-20 14:02:37 +01:00

43 lines
967 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 Encart 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 (Encart $encart) {
if ($encart->picture) {
$encart->picture = Utils::storeImage($encart->picture, $encart->getTable());
}
});
static::updating(function (Encart $encart) {
if ($encart->picture) {
$encart->picture = Utils::storeImage($encart->picture, $encart->getTable());
}
});
parent::boot();
}
}