ldc-doux/app/Models/Advice.php

54 lines
1.5 KiB
PHP
Raw Normal View History

2021-12-15 18:17:17 +01:00
<?php
namespace App\Models;
use App\Lib\Utils;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class Advice extends Model
{
use HasFactory;
protected $fillable = [
'title1',
'title2',
'picture1',
2021-12-20 14:02:37 +01:00
'alt_text_picture1',
2021-12-15 18:17:17 +01:00
'picture2',
2021-12-20 14:02:37 +01:00
'alt_text_picture2',
2021-12-15 18:17:17 +01:00
'picture3',
2021-12-20 14:02:37 +01:00
'alt_text_picture3',
2021-12-15 18:17:17 +01:00
'text1',
'text2',
];
protected static function boot()
{
static::creating(function (Advice $advice) {
if ($advice->picture1) {
$advice->picture1 = Utils::storeImage($advice->picture1, $advice->getTable());
}
if ($advice->picture2) {
$advice->picture2 = Utils::storeImage($advice->picture2, $advice->getTable());
}
if ($advice->picture3) {
$advice->picture3 = Utils::storeImage($advice->picture3, $advice->getTable());
}
});
static::updating(function (Advice $advice) {
if ($advice->picture1) {
$advice->picture1 = Utils::storeImage($advice->picture1, $advice->getTable());
}
if ($advice->picture2) {
$advice->picture2 = Utils::storeImage($advice->picture2, $advice->getTable());
}
if ($advice->picture3) {
$advice->picture3 = Utils::storeImage($advice->picture3, $advice->getTable());
}
});
parent::boot();
}
}