ldc-tregalette/app/Models/KlubBloc.php
2023-12-22 15:09:55 +01:00

53 lines
1.6 KiB
PHP

<?php
namespace App\Models;
use App\Lib\Helpers\FileStorageHelper;
use App\Traits\Models\ActivityLog;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
/**
* @property string $picture Path de l'image de la section "le klub" (640px * 637px).
* @property string $picture_alt Attribut alt de l'image de la section "le klub".
* @property string $picture_title Attribut title de l'image de la section "le klub".
* @property-read \Carbon\Carbon $created_at Created date.
* @property-read \Carbon\Carbon $updated_at Updated date.
*/
class KlubBloc extends Model
{
use ActivityLog;
use HasFactory;
/**
* The attributes that are mass assignable.
*
* @var array<int, string>
*/
protected $fillable = [
'picture',
'picture_alt',
'picture_title',
];
/**
* Perform any actions required after the model boots.
*
* @return void
*/
protected static function booted(): void
{
static::creating(function () {
throw new \RuntimeException("Creating a new klub section is not authorized");
});
static::updating(function (self $model) {
$model->picture = FileStorageHelper::storeFile($model, $model->picture, true);
});
static::updated(function (self $model) {
FileStorageHelper::removeOldFile($model, 'picture');
});
static::deleting(function () {
throw new \RuntimeException('Deleting the klub section is not authorized');
});
}
}