New-OMIS/app/Models/Permission.php

51 lines
1.3 KiB
PHP
Raw Normal View History

2024-04-05 05:22:15 +00:00
<?php
2024-04-07 12:14:05 +00:00
namespace App\Models;
2024-04-05 05:22:15 +00:00
use App\Modules\Models\User;
use App\Modules\Models\Role;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class Permission extends Model
{
use HasFactory;
protected $fillable= [
'name', 'slug', 'visibility','status', 'availability','is_deleted','group_name',
'deleted_at','created_by','last_updated_by','last_deleted_by'
];
protected $appends = [
'visibility_text', 'status_text', 'availability_text', 'thumbnail_path', 'image_path'
];
function getVisibilityTextAttribute(){
return ucwords(str_replace('_', ' ', $this->visibility));
}
function getStatusTextAttribute(){
return ucwords(str_replace('_', ' ', $this->status));
}
function getAvailabilityTextAttribute(){
return ucwords(str_replace('_', ' ', $this->availability));
}
function creator(){
return $this->belongsTo(User::class,'created_by');
}
function getImagePathAttribute(){
return $this->path.'/'. $this->image;
}
function getThumbnailPathAttribute(){
return $this->path.'/thumb/'. $this->image;
}
public function roles(){
return $this->belongsToMany(Role::class,'role_has_permissions');
}
}