Пример #1
0
 public function destroy($id)
 {
     $role = Role::whereId($id)->first();
     $role->delete();
     alert()->success('...', 'Rôle supprimé !')->autoclose(3500);
     return redirect('/entrust/roles');
 }
 /** @test */
 public function it_checks_if_a_user_has_at_least_one_out_of_a_collection_of_roles()
 {
     $user = factory(User::class)->create();
     $role_1 = factory(Role::class)->create(['name' => 'role1', 'display_name' => 'Role1']);
     $role_2 = factory(Role::class)->create(['name' => 'role2', 'display_name' => 'Role2']);
     $user->addRole($role_2);
     $this->assertTrue($user->hasRole(Role::all()));
     $this->assertFalse($user->hasRole(Role::whereId($role_1->id)->get()));
 }
Пример #3
0
 public function update($id)
 {
     $role = Role::whereId($id)->firstOrFail();
     $input = Input::all();
     $rules = array('name' => 'required', 'display_name' => 'required');
     $validator = Validator::make($input, $rules);
     if ($validator->fails()) {
         return Response::json(['success' => false, 'errors' => $validator->getMessageBag()->toArray()]);
     } else {
         $role->name = Input::get('name');
         $role->display_name = Input::get('display_name');
         $role->description = Input::get('description');
         $role->save();
         return Response::json(['success' => true, 'message' => 'The role has been updated!']);
     }
 }
Пример #4
0
 public static function getDefaultRole()
 {
     $defaultRoleId = Option::getValueByKey('default_role_id');
     $defaultRole = Role::whereId($defaultRoleId)->first();
     if (!$defaultRole) {
         throw new SystemException(SystemException::DefaultRoleNotDefined);
     }
     return $defaultRole;
 }
 /**
  * Update the specified resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function update(Request $request, $id)
 {
     if (\Auth::user()->roles[0]->can('menu-update')) {
         $input = $request->all();
         $input['url'] = "admin/" . str_plural(Str::lower($input['name'] != 'Dashboard' ? $string = str_replace(" ", "_", $input['name']) : ''));
         $menu = $this->menus->findOrFail($id);
         $menu->update($input);
         $menu->roles()->detach();
         foreach ($request->roles as $_id) {
             $role = Role::whereId($_id)->first();
             $menu->assign($role);
         }
         \Session::flash('flash_message', 'Menu updated!');
         return \Redirect::route('admin.menus.index', [])->withMessage(trans('acl::menu.menus-controller-successfully_updated'));
     }
     return \Redirect::route('admin.menus.index')->withErrors(trans('acl::dashboard.unauthorized_access'));
 }