private function retrieveRoleIdByName($roleName) { $role = Roles::where("name", $roleName)->first(); if ($role === null) { throw new BadRequestHttpException("Provided role does not exists."); } return $role->id; }
public function handle($request, Closure $next) { $user = Auth::user(); if ($user === null) { throw new HttpException(500, "Failed to retrieve authenticated user."); } $role = Roles::where('id', $user->role_id)->firstOrFail(); if ($role->name !== "Administrator") { throw new AccessDeniedHttpException("Permission are required to access this resources."); } return $next($request); }
public function handle($request, Closure $next) { if ($this->auth->check()) { $user = Auth::user(); $role = Roles::where('id', $user->role_id)->firstOrFail(); if ($role->name === "Administrator") { return redirect()->intended('/administration'); } return redirect()->intended('/'); } return $next($request); }
/** * Display a listing of the resource based on a search parameter. * * @return Response */ public function search() { $rules = array('search' => 'required'); $validator = Validator::make(Input::all(), $rules); // process the validation if ($validator->fails()) { return Redirect::to('roles')->withErrors($validator)->withInput(); } else { // search $records = Roles::where('rl_name', 'LIKE', '%' . Input::get('search') . '%')->orWhere('rl_description', 'LIKE', '%' . Input::get('search') . '%')->select('id', 'rl_name', 'rl_description', 'rl_enabled', 'created_by', 'updated_by')->orderBy('id')->paginate(10); // Get the records for the current module based on the model created. return view('admin.roles.index')->with('Records', $records); } }
public function send_data(Request $request) { #----------- get the role name $arr = array(); $arr['role_name'] = $request->selected; #----------- fetch the id of that role $id = Roles::where('type', $arr['role_name'])->first(); #---------- fetch the operations and id of the operations $operations = Operations::all()->sort(); #---------- fetch resources and id of resources $resources = Resources::all(); #---------- for counting the number of rows that match the condition $count = Privileges::where('rolesid', $id->id)->count(); #---------- fetching data upto count $privileges = Privileges::where('rolesid', $id->id)->take($count)->get(); $str = "<div class = 'table'>"; #---------- now loop that consists of other loops #---------- it loops around the number of resources foreach ($resources as $resource_info) { $i = 0; $str .= "<div class='row'>"; $str .= "<br>" . "<div class='col-lg-4 '>"; $str .= $resource_info->name . ":---->"; $str .= "</div>"; $oper_info = array(); if (!empty($privileges)) { #--------to decide how many privileges will be there for a particular resource foreach ($privileges as $priv_info) { if ($priv_info->resourceid == $resource_info->id) { $oper_info[$i] = $priv_info->operationid; $i++; } } sort($oper_info); $number_of_actions = 0; $count_array = count($oper_info); $a = array(); #------------it is necessary to check for non empty values if (!empty($oper_info)) { foreach ($operations as $key => $value) { $str .= "<div class='col-lg-2 '>"; if ($number_of_actions < $count_array && $value->id == $oper_info[$number_of_actions]) { $str .= $value->actions . " : " . ' <input type="checkbox" ' . 'onchange="my_dynamic_function(this.checked, ' . $id->id . ',' . $resource_info->id . ', ' . $value->id . ')" ' . ' name="option" value="" checked = "checked" >-----'; if ($number_of_actions < $count_array) { $number_of_actions++; } } else { $str .= $value->actions . " : " . ' <input type="checkbox" ' . 'onchange="my_dynamic_function(this.checked, ' . $id->id . ',' . $resource_info->id . ', ' . $value->id . ')" ' . ' name="option" value="" >-----'; } $str .= "</div>"; } } else { foreach ($operations as $key => $value) { $str .= "<div class='col-lg-2 '>"; $str .= $value->actions . " : " . ' <input type="checkbox" ' . 'onchange="my_dynamic_function(this.checked, ' . $id->id . ',' . $resource_info->id . ', ' . $value->id . ')" ' . ' name="option" value="" >-----'; $str .= "</div>"; } } } $str .= "<br>"; $str .= "</div>"; } $str .= '</div>'; return response()->json($str); }
/** * Show the form for editing the specified resource. * * @param int $id * @return Response */ public function edit($id) { $this->authorize(new Permissions()); $Item = User::find($id); $this->authorize($Item); $usr_role = \Auth::user()->usr_role; $rlList = Roles::where('rl_enabled', '1')->where('id', '>=', $usr_role)->select('id', 'rl_name')->get(); return view('admin.user.edit')->with('Item', $Item)->with('rlList', $rlList); }