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

69 lines
1.8 KiB
PHP

<?php
namespace App\Models;
use App\Lib\ToolboxHelper;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class WhoareweBrand extends Model
{
use HasFactory;
/**
* The attributes that are fillable.
*
* @var array
*/
#[\Override]
protected $fillable = [
'title',
'text',
'picture1',
'alt_text_picture1',
'picture2',
'alt_text_picture2',
'picture_position_center',
'picture_position_left',
'picture_position_right',
];
/**
* The "booted" method of the model.
*
* @return void
*/
protected static function boot()
{
static::creating(function (WhoareweBrand $whoarewebrand): void {
if ($whoarewebrand->picture1) {
$whoarewebrand->picture1 = ToolboxHelper::storeImage(
$whoarewebrand->picture1,
$whoarewebrand->getTable()
);
}
if ($whoarewebrand->picture2) {
$whoarewebrand->picture2 = ToolboxHelper::storeImage(
$whoarewebrand->picture2,
$whoarewebrand->getTable()
);
}
});
static::updating(function (WhoareweBrand $whoarewebrand): void {
if ($whoarewebrand->picture1) {
$whoarewebrand->picture1 = ToolboxHelper::storeImage(
$whoarewebrand->picture1,
$whoarewebrand->getTable()
);
}
if ($whoarewebrand->picture2) {
$whoarewebrand->picture2 = ToolboxHelper::storeImage(
$whoarewebrand->picture2,
$whoarewebrand->getTable()
);
}
});
parent::boot();
}
}