41 lines
917 B
PHP
41 lines
917 B
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use App\Enums\Page;
|
|
use App\Lib\Utils;
|
|
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',
|
|
'alt_text_picture',
|
|
'text',
|
|
];
|
|
|
|
protected static function boot()
|
|
{
|
|
static::creating(function (Picto $picto) {
|
|
if ($picto->picture) {
|
|
$picto->picture = Utils::storeImage($picto->picture, $picto->getTable());
|
|
}
|
|
});
|
|
|
|
static::updating(function (Picto $picto) {
|
|
if ($picto->picture) {
|
|
$picto->picture = Utils::storeImage($picto->picture, $picto->getTable());
|
|
}
|
|
});
|
|
parent::boot();
|
|
}
|
|
}
|