ldc-doux/app/Models/Encart.php

44 lines
967 B
PHP
Raw Normal View History

2021-12-08 17:32:56 +01:00
<?php
namespace App\Models;
use App\Enums\Page;
2021-12-09 17:31:10 +01:00
use App\Lib\Utils;
2021-12-08 17:32:56 +01:00
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
2021-12-13 16:55:12 +01:00
use Kwaadpepper\Enum\Traits\CastsEnums;
2021-12-08 17:32:56 +01:00
class Encart extends Model
{
use HasFactory;
2021-12-13 16:55:12 +01:00
use CastsEnums;
2021-12-08 17:32:56 +01:00
2021-12-13 16:55:12 +01:00
public $enumCasts = [
2021-12-08 17:32:56 +01:00
'page' => Page::class
];
2021-12-09 17:31:10 +01:00
protected $fillable = [
'title',
'subtitle',
'text',
2021-12-20 14:02:37 +01:00
'picture',
'alt_text_picture',
2021-12-09 17:31:10 +01:00
];
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();
}
2021-12-08 17:32:56 +01:00
}