/** * Update the specified resource in storage. * * @param \Illuminate\Http\Request $request * @param int $id * @return \Illuminate\Http\Response */ public function update(RoleRequest $request, $id) { $role = Role::findOrFail($id); $role->name = $request->get('name'); $role->save(); $role->syncPermission($request->get('permissions', [])); \Notification::success('acl.roles.update.success'); return redirect()->route('admin.roles.index'); }
/** * Method for stroring a new role in the database. * * @param RoleRequest $request * @return mixed */ public function store(RoleRequest $request) { $role = new Role($request->all()); $role->save(); if (is_null($request->get('permissions'))) { $role->permissions()->sync([]); } else { $role->permissions()->sync($request->get('permissions')); } return redirect(route('rbac.roles.index'))->withSuccess('You have successfully created a new role.'); }
public function update($id, RoleRequest $request) { $this->role->save($id, $request->all()); if ($request->ajax()) { return response()->json(['status' => trans('messages.saved'), 'type' => 'success']); } $route = $request->get('task') == 'apply' ? route('admin.roles.edit', $id) : route('admin.roles.index'); return redirect($route)->with(['status' => trans('messages.saved'), 'type' => 'success']); }
/** * Function Store * to Save/Update Brand From Brand Form * @Request @Name,@Code etc * * @return json */ public function onStore(\App\Http\Requests\RoleRequest $request) { $is_exist = \App\Models\Role::where('name', $request->get('name'))->where('id', '!=', $request->get('id'))->get(['id'])->first(); if ($is_exist) { $param['error'] = true; $param['message'] = Lang::get('message.role unique name'); return json_encode($param); } $role = new \App\Models\Role(); if ($request->has('id')) { $role = $role->where('id', $request->get('id'))->first(); $role->updated_at = date('Y-m-d H:i:s'); $role->updated_by = Auth::user()->id; } else { $role->created_at = date('Y-m-d H:i:s'); $role->created_by = Auth::user()->id; } $role->name = $request->get('name'); $role->description = $request->get('description'); $role->active = $request->get('active') ? $request->get('active') : 0; $role->authorize = $request->get('authorize') ? $request->get('authorize') : 0; $role->save(); $param['message'] = $request->get('id') ? Lang::get('info.updated') : Lang::get('info.inserted'); $param['error'] = false; return json_encode($param); }