master crud setup
This commit is contained in:
49
app/Models/Role/Role.php
Normal file
49
app/Models/Role/Role.php
Normal file
@ -0,0 +1,49 @@
|
||||
<?php
|
||||
|
||||
namespace App\Modules\Models\Role;
|
||||
|
||||
use App\Modules\Models\Permission\Permission;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Role extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
protected $fillable= [
|
||||
'name', 'slug', 'visibility','status', 'availability','is_deleted',
|
||||
'deleted_at','created_by','last_updated_by','last_deleted_by'
|
||||
];
|
||||
|
||||
protected $appends = [
|
||||
'visibility_text', 'status_text', 'availability_text', 'thumbnail_path', 'image_path'
|
||||
];
|
||||
|
||||
public function permissions(){
|
||||
return $this->belongsToMany(Permission::class,'role_has_permissions');
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user