45 lines
1,004 B
PHP
45 lines
1,004 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
|
|
*/
|
|
#[\Override]
|
|
protected $fillable = [
|
|
'title',
|
|
'picture',
|
|
'alt_text_picture',
|
|
];
|
|
|
|
/**
|
|
* The "booted" method of the model.
|
|
*
|
|
* @return void
|
|
*/
|
|
protected static function boot()
|
|
{
|
|
static::creating(function (BasicBanner $banner): void {
|
|
if ($banner->picture) {
|
|
$banner->picture = ToolboxHelper::storeImage($banner->picture, $banner->getTable());
|
|
}
|
|
});
|
|
|
|
static::updating(function (BasicBanner $banner): void {
|
|
if ($banner->picture) {
|
|
$banner->picture = ToolboxHelper::storeImage($banner->picture, $banner->getTable());
|
|
}
|
|
});
|
|
parent::boot();
|
|
}
|
|
}
|