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

72 lines
1.4 KiB
PHP

<?php
namespace App\Models;
use App\Lib\ToolboxHelper;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class HomepageSlide extends Model
{
use HasFactory;
/**
* The attributes that are fillable.
*
* @var array
*/
#[\Override]
protected $fillable = [
'title',
'picture',
'alt_text_picture',
'url',
'new_tab',
'status',
];
/**
* The attributes that should be cast.
*
* @var array
*/
#[\Override]
protected $casts = [
'new_tab' => 'bool',
'status' => 'bool',
];
/**
* The "booted" method of the model.
*
* @return void
*/
protected static function booted()
{
static::creating(function (HomepageSlide $slide): void {
self::manageFields($slide);
});
static::updating(function (HomepageSlide $slide): void {
self::manageFields($slide);
});
}
// * METHODS
/**
* Common methods function.
*
* @param Model $model
* @return void
*/
private static function manageFields(Model $model)
{
if ($model->link) {
ToolboxHelper::assertNoInternalBoUrls('url', $model->url);
}
if ($model->picture) {
$model->picture = ToolboxHelper::storeImage($model->picture, $model->getTable());
}
}
}