53 lines
1.5 KiB
PHP
53 lines
1.5 KiB
PHP
<?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',
|
|
'alt_text_picture1',
|
|
'picture2',
|
|
'alt_text_picture2',
|
|
'picture3',
|
|
'alt_text_picture3',
|
|
'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();
|
|
}
|
|
}
|