Ejemplo n.º 1
0
 /**
  * Run the seeder.
  */
 public function run()
 {
     Role::unguard();
     Role::create(['name' => 'admin']);
     Role::create(['name' => 'superuser']);
     Role::create(['name' => 'noaccess']);
 }
 /**
  *  Testing if permission is attached to role.
  */
 public function testShouldAttachPermissionToRole()
 {
     $permission = $this->createPermission('users.index');
     $role = Role::where(['name' => 'admin'])->first();
     $permission->roles()->attach($role);
     $this->seePermissionAttachedToRoleInDatabase($permission, $role);
     $this->assertTrue($permission->roles()->get()->contains($role->id));
     $this->assertInstanceOf('Artesaos\\Defender\\Pivots\\PermissionRolePivot', $role->permissions->first()->pivot);
 }
Ejemplo n.º 3
0
 public function index()
 {
     $results = ['columns' => [['名称', 'name'], ['邮箱', 'email'], ['创建时间', 'created_at'], ['操作', 'buttons', function ($data) {
         $buttons = [['编辑']];
         if (!$data->hasRole(config('defender.superuser_role', 'superuser'))) {
             array_push($buttons, ['分配角色', '#modal']);
         }
         return $buttons;
     }]]];
     $collection = Role::all();
     $roles = [];
     foreach ($collection as $role) {
         array_push($roles, ['label' => $role->name, 'value' => $role->id]);
     }
     $paginate = Admin::with('roles')->orderBy('created_at', 'desc')->paginate();
     $results['items'] = $paginate;
     return $this->view('forone::' . self::URI . '.index', compact('results', 'roles'));
 }
Ejemplo n.º 4
0
 /**
  * Update the specified resource in storage.
  *
  * @param  int  $id
  * @return Response
  */
 public function update($id, UpdateRoleRequest $request)
 {
     $name = $request->get('name');
     $count = Role::whereName($name)->where('id', '!=', $id)->count();
     if ($count > 0) {
         return $this->redirectWithError('角色名称不能重复');
     }
     $data = $request->only('name');
     Role::findOrFail($id)->update($data);
     return redirect()->route('admin.roles.index');
 }
Ejemplo n.º 5
0
 /**
  *
  */
 private function initRoles()
 {
     return Role::create(['name' => config('defender.superuser_role')]);
 }