71 lines
1.7 KiB
PHP
71 lines
1.7 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use App\Lib\Utils;
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Support\Facades\File;
|
|
use Spatie\Translatable\HasTranslations;
|
|
|
|
class PictoBrand extends Model
|
|
{
|
|
use HasFactory;
|
|
use HasTranslations;
|
|
|
|
/**
|
|
* The attributes that are mass assignable.
|
|
*
|
|
* @var array
|
|
*/
|
|
protected $fillable = [
|
|
'title',
|
|
'picture',
|
|
'alt_text_picture',
|
|
'text',
|
|
];
|
|
|
|
/**
|
|
* The attributes that are translatable.
|
|
*
|
|
* @var array
|
|
*/
|
|
public $translatable = [
|
|
'title',
|
|
'picture',
|
|
'alt_text_picture',
|
|
'text',
|
|
];
|
|
|
|
/**
|
|
* Perform any actions required after the model boots.
|
|
*
|
|
* @return void
|
|
*/
|
|
protected static function boot()
|
|
{
|
|
static::creating(function (PictoBrand $pictoBrand) {
|
|
if (is_a($pictoBrand->picture, "SplFileInfo")) {
|
|
$pictoBrand->picture = Utils::storeImage($pictoBrand->picture, $pictoBrand->getTable());
|
|
}
|
|
});
|
|
|
|
static::updating(function (PictoBrand $pictoBrand) {
|
|
if (is_a($pictoBrand->picture, "SplFileInfo")) {
|
|
$pictoBrand->picture = Utils::storeImage($pictoBrand->picture, $pictoBrand->getTable());
|
|
}
|
|
});
|
|
|
|
static::deleted(function (PictoBrand $pictoBrand) {
|
|
if ($pictoBrand->picture) {
|
|
$urlPicture = public_path() . $pictoBrand->picture;
|
|
if ($urlPicture) {
|
|
if (File::exists($urlPicture)) {
|
|
File::delete($urlPicture);
|
|
}
|
|
}
|
|
}
|
|
});
|
|
parent::boot();
|
|
}
|
|
}
|