Current File : //home/tradevaly/new.tradevaly.com.bd/app/Models/Role.php |
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class Role extends Model
{
use HasFactory;
protected $guarded = [''];
// public function permissions()
// {
// return $this->belongsToMany(Permission::class, 'role_has_permissions');
// }
public function get_permissions()
{
return $this->hasMany(RoleHasPermission::class);
}
public function permission()
{
return $this->belongsTo(Permission::class);
}
// GET PERMISSIONS
public static function permissions()
{
// return RoleHasPermission::select('permission_id', 'role_id')
// ->with(['permission' => function ($q) {
// $q->select('id', 'name', 'route_name');
// }])->get()->groupBy('role_id')->toArray();
return RoleHasPermission::select('permission_id', 'role_id')->get()->groupBy('role_id')->toArray();
}
public function admin(){
return $this->belongsToMany(Role::class,'role_id','id');
}
}