ldc-loue/app/Models/Engagement.php
2022-09-19 09:10:04 +00:00

83 lines
1.7 KiB
PHP

<?php
namespace App\Models;
use App\Enums\Engagements\EngagementType;
use App\Traits\Models\MiniCrudModel;
use App\Lib\ToolboxHelper;
use Illuminate\Database\Eloquent\Model;
use Kwaadpepper\Enum\Traits\CastsEnums;
class Engagement extends Model
{
use CastsEnums;
use MiniCrudModel;
/**
* The primary key for the model.
*
* @var string
*/
protected $primaryKey = 'type';
/**
* Indicates if the IDs are auto-incrementing.
*
* @var boolean
*/
public $incrementing = false;
/**
* The attributes that should be cast.
*
* @var array
*/
protected $casts = [
'data' => 'array'
];
/**
* The attributes that should be cast to Enums.
*
* @var array
*/
protected $enumCasts = [
'type' => EngagementType::class
];
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = [
'title',
'slug',
'seo_title',
'seo_description',
'banner',
'banner_title',
'banner_alt',
'type',
'data'
];
/**
* Perform any actions required after the model boots.
*
* @return void
*/
protected static function booted()
{
static::creating(function (self $model) {
$model->banner = ToolboxHelper::storeImage($model, $model->banner);
});
static::updating(function (self $model) {
ToolboxHelper::removeOldImage($model, 'banner');
$model->banner = ToolboxHelper::storeImage($model, $model->banner);
});
static::deleted(function (self $model) {
ToolboxHelper::removeImage($model, 'banner');
});
}
}