public static function getPermission($controller_type, $controller_id = null, $return = false) { //check permisssion against user if (Auth::guest()) { $user = \Bootleg\Cms\User::find(1); //select the guest row. } else { $user = \Auth::user(); } $controller_type = trim($controller_type, '/\\'); //$controller_type = (addslashes($controller_type)); //$p = Permission::where('controller_type', $controller_type)->first(); //dd($p->id); //a horrible looking query that grabs the permissions for a user. $perm = Permission::where(function ($query) use($controller_type, $controller_id) { $query->where('controller_type', '=', $controller_type)->where(function ($query) use($controller_id) { $query->where('controller_id', '=', $controller_id)->orWhere('controller_id', '=', '*'); }); })->where(function ($query) use($user) { $query->where(function ($query) use($user) { //where user $query->where(function ($query) use($user) { $query->where('requestor_id', '=', $user->id)->orWhere('requestor_id', '=', '*'); })->where('requestor_type', '=', 'user'); })->orWhere(function ($query) use($user) { //where role $query->where(function ($query) use($user) { $query->where('requestor_id', '=', $user->role_id)->orWhere('requestor_id', '=', '*'); })->where('requestor_type', '=', 'role'); }); })->where(function ($query) { $app_id = Application::getApplication()->id; $query->where('application_id', $app_id)->orWhere('application_id', '*'); })->orderBy('controller_id', 'desc')->orderBy('requestor_id', 'desc')->orderBy('requestor_type', 'desc')->get(); //dd($perm); $return = new stdClass(); $return->result = false; foreach ($perm as $p) { if ($p->x == 1) { $return->result = true; $return->picked = $p; break; } elseif ($p->x == 0) { $return->result = false; $return->picked = $p; break; } else { //var_dump($p->id); //we are inheriting from the enxt level up. } } $return->set = $perm; return $return; }
/** * Remove the specified resource from storage. * * @param int $id * @return Response */ public function destroy($id) { $this->user->find($id)->delete(); return Redirect::route('users.index'); }