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