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

66 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 WhoareweDescription extends Model
{
use HasFactory;
/**
* Fillable fields.
*
* @var array
*/
#[\Override]
protected $fillable = [
'title',
'text',
'picture1',
'alt_text_picture1',
'picture2',
'alt_text_picture2',
];
/**
* The "booted" method of the model.
*
* @return void
*/
protected static function boot()
{
static::creating(function (WhoareweDescription $whoarewedescription): void {
if ($whoarewedescription->picture1) {
$whoarewedescription->picture1 = ToolboxHelper::storeImage(
$whoarewedescription->picture1,
$whoarewedescription->getTable()
);
}
if ($whoarewedescription->picture2) {
$whoarewedescription->picture2 = ToolboxHelper::storeImage(
$whoarewedescription->picture2,
$whoarewedescription->getTable()
);
}
});
static::updating(function (WhoareweDescription $whoarewedescription): void {
if ($whoarewedescription->picture1) {
$whoarewedescription->picture1 = ToolboxHelper::storeImage(
$whoarewedescription->picture1,
$whoarewedescription->getTable()
);
}
if ($whoarewedescription->picture2) {
$whoarewedescription->picture2 = ToolboxHelper::storeImage(
$whoarewedescription->picture2,
$whoarewedescription->getTable()
);
}
});
parent::boot();
}
}