New-OMIS/app/Models/Permission/Permission.php
2024-04-05 11:07:15 +05:45

51 lines
1.3 KiB
PHP

<?php
namespace App\Modules\Models\Permission;
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');
}
}