69 lines
2 KiB
PHP
69 lines
2 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use App\Enums\StaticPageType;
|
|
use App\Enums\Users\RoleEnum;
|
|
use App\Traits\Models\ActivityLog;
|
|
use Illuminate\Auth\Access\AuthorizationException;
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
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-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;
|
|
use HasFactory;
|
|
|
|
/**
|
|
* The attributes that are mass assignable.
|
|
*
|
|
* @var array<int, string>
|
|
*/
|
|
protected $fillable = [
|
|
'type',
|
|
'title',
|
|
'anchor',
|
|
];
|
|
|
|
/**
|
|
* The attributes that should be cast.
|
|
*
|
|
* @var array<string, string>
|
|
*/
|
|
protected $casts = [
|
|
'type' => StaticPageType::class,
|
|
];
|
|
|
|
/**
|
|
* Perform any actions required after the model boots.
|
|
*
|
|
* @return void
|
|
*/
|
|
protected static function booted(): void
|
|
{
|
|
static::creating(function (self $model) {
|
|
// * Prevent user elevation privileges
|
|
throw_if(
|
|
auth('backend')->user() and auth('backend')->user()->role->value() < RoleEnum::conceptor->value(),
|
|
AuthorizationException::class
|
|
);
|
|
});
|
|
static::deleting(function (self $model) {
|
|
// // * Prevent user elevation privileges
|
|
throw_if(
|
|
auth('backend')->user() and auth('backend')->user()->role->value() < RoleEnum::conceptor->value(),
|
|
AuthorizationException::class
|
|
);
|
|
});
|
|
}
|
|
}
|