ldc-volena/app/Models/Sticky.php

71 lines
2.1 KiB
PHP

<?php
namespace App\Models;
use App\Enums\StaticPageType;
use App\Enums\StickiesColorEnum;
use App\Enums\Users\RoleEnum;
use App\Traits\Models\ActivityLog;
use Illuminate\Auth\Access\AuthorizationException;
use Illuminate\Database\Eloquent\Model;
/**
* @property int $id
* @property \App\Enums\StaticPageType $type Page type (StaticPageEnum).
* @property string $title Title for the sticky.
* @property string $anchor Anchor for the sticky.
* @property \App\Enums\StickiesColorEnum $color Color of the button (StickiesColorEnum).
* @property-read \Illuminate\Support\Carbon $created_at Created date.
* @property-read \Illuminate\Support\Carbon $updated_at Updated date.
*
* @property-read \App\Models\ActivityLog $activityLogs Activities logs One-to-many relationship.
*/
class Sticky extends Model
{
use ActivityLog;
/**
* The attributes that are mass assignable.
*
* @var list<string>
*/
protected $fillable = [
'type',
'title',
'anchor',
'color',
];
/**
* The attributes that should be cast.
*
* @var array<string, string>
*/
protected $casts = [
'type' => StaticPageType::class,
'color' => StickiesColorEnum::class,
];
/**
* Perform any actions required after the model boots.
*
* @return void
*/
protected static function booted(): void
{
static::creating(function () {
// * Prevent user elevation privileges
throw_if(
auth('backend')->user() and auth('backend')->user()->role->value() < RoleEnum::conceptor->value(),
AuthorizationException::class
);
});
static::deleting(function () {
// // * Prevent user elevation privileges
throw_if(
auth('backend')->user() and auth('backend')->user()->role->value() < RoleEnum::conceptor->value(),
AuthorizationException::class
);
});
}
}