Esempio n. 1
0
 /**
  * Handle an incoming request.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  \Closure  $next
  * @return mixed
  */
 public function handle($request, Closure $next, $permission)
 {
     if (Auth::user()->id == 1) {
         return $next($request);
     }
     $idP = Permission::where('ip', $permission)->value('id');
     $rol = Auth::user()->rol;
     if (!Permissions_assigned::where('role', $rol)->where('permission', $idP)->first()) {
         return redirect('auth/logout');
     }
     return $next($request);
 }
Esempio n. 2
0
 public function hasPermissions($permissions, $all = false)
 {
     if ($this->id == 1) {
         return true;
     }
     if (!$all) {
         foreach ($permissions as $permission) {
             $idP = Permission::where('ip', $permission)->value('id');
             if (Permissions_assigned::where('role', $this->rol)->where('permission', $idP)->first()) {
                 return true;
             }
         }
         return false;
     } else {
         foreach ($permissions as $permission) {
             $idP = Permission::where('ip', $permission)->value('id');
             if (!Permissions_assigned::where('role', $this->rol)->where('permission', $idP)->first()) {
                 return false;
             }
         }
         return true;
     }
 }
Esempio n. 3
0
 public function eliminar($id)
 {
     if (!Role::where('id', $id)->first()) {
         return Response()->json(['status' => 'danger', 'message' => 'Este rol no existe']);
     }
     Role::where('id', $id)->delete();
     Permissions_assigned::where('role', $id)->delete();
     return Response()->json(['status' => 'success', 'message' => 'Rol eliminado']);
 }