ldc-domaine-de-lanvaux/app/Models/BasicBanner.php

44 lines
975 B
PHP

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