ldc-doux/app/Models/Picto.php

42 lines
917 B
PHP
Raw Normal View History

2021-12-13 16:55:12 +01:00
<?php
namespace App\Models;
use App\Enums\Page;
2021-12-15 10:09:39 +01:00
use App\Lib\Utils;
2021-12-13 16:55:12 +01:00
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Kwaadpepper\Enum\Traits\CastsEnums;
class Picto extends Model
{
use HasFactory;
use CastsEnums;
public $enumCasts = [
'page' => Page::class
];
protected $fillable = [
'picture',
2021-12-20 14:02:37 +01:00
'alt_text_picture',
2021-12-13 16:55:12 +01:00
'text',
];
2021-12-15 10:09:39 +01:00
protected static function boot()
{
static::creating(function (Picto $picto) {
if ($picto->picture) {
$picto->picture = Utils::storeImage($picto->picture, $picto->getTable());
}
});
2021-12-13 16:55:12 +01:00
2021-12-15 10:09:39 +01:00
static::updating(function (Picto $picto) {
if ($picto->picture) {
$picto->picture = Utils::storeImage($picto->picture, $picto->getTable());
}
});
parent::boot();
}
2021-12-13 16:55:12 +01:00
}