ldc-domaine-de-lanvaux/app/Models/HomepageHook.php
2026-10-27 15:12:56 +01:00

47 lines
1.1 KiB
PHP

<?php
namespace App\Models;
use App\Lib\ToolboxHelper;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class HomepageHook extends Model
{
use HasFactory;
/**
* Fillable fields.
*
* @var array
*/
#[\Override]
protected $fillable = [
'title',
'subtitle',
'text',
'picture',
'alt_text_picture',
];
/**
* The "booted" method of the model.
*
* @return void
*/
protected static function boot()
{
static::creating(function (HomepageHook $homepagehook): void {
if ($homepagehook->picture) {
$homepagehook->picture = ToolboxHelper::storeImage($homepagehook->picture, $homepagehook->getTable());
}
});
static::updating(function (HomepageHook $homepagehook): void {
if ($homepagehook->picture) {
$homepagehook->picture = ToolboxHelper::storeImage($homepagehook->picture, $homepagehook->getTable());
}
});
parent::boot();
}
}