Inheritance: extends Illuminate\Database\Eloquent\Model, implements Illuminate\Contracts\Auth\Authenticatable, implements Illuminate\Contracts\Auth\CanResetPassword, use trait Illuminate\Auth\Authenticatable, use trait Illuminate\Auth\Passwords\CanResetPassword, use trait Artesaos\Defender\Traits\HasDefender
Exemple #1
0
 /**
  * Creating a Role to User.
  */
 public function testCommandShouldMakeARoleToUser()
 {
     $this->artisan('defender:make:role', ['name' => 'user.role', '--user' => 1]);
     $this->seeInDatabase(config('defender.role_table', 'roles'), ['name' => 'user.role']);
     $user = User::find(1);
     $this->assertEquals('user.role', $user->roles->where('name', 'user.role')->first()->name);
 }
Exemple #2
0
 /**
  * {@inheritdoc}
  */
 public function setUp()
 {
     parent::setUp();
     $this->migrate([$this->stubsPath('database/migrations'), $this->resourcePath('migrations')]);
     $this->seed(['UserTableSeeder', 'RoleTableSeeder']);
     $this->app->singleton('Illuminate\\Contracts\\Debug\\ExceptionHandler', 'Orchestra\\Testbench\\Exceptions\\Handler');
     $this->defender = new Defender($this->app, $this->app['defender.role'], $this->app['defender.permission']);
     $this->defender->setUser(User::first());
 }
 /**
  * Create and Attach a Role to User.
  * @param string     $role Role name.
  * @param User|array $user User or array of where clausules.
  * @return array Array containing $role and $user created.
  */
 protected function createAndAttachRole($role, $user)
 {
     $role = $this->createRole($role);
     if (!$user instanceof User) {
         $user = User::where($user)->first();
     }
     $role->users()->attach($user);
     $this->seeRoleAttachedToUserInDatabase($role, $user);
     return [$role, $user];
 }
 /**
  * Create and Attach a Permission to User.
  * @param string $permission
  * @param Role $role Role or array of where clausules.
  * @param string $readableName Permission readable name.
  * @return array Array containing created $permission and $role.
  */
 protected function createAndAttachPermissionToRole($permission, $role, $readableName = null)
 {
     $permission = $this->createPermission($permission, $readableName);
     if (!$role instanceof Role) {
         $role = User::where($role)->first();
     }
     $permission->roles()->attach($role);
     $this->seePermissionAttachedToRoleInDatabase($permission, $role);
     return [$permission, $role];
 }
Exemple #5
0
 /**
  * Run the seeder.
  */
 public function run()
 {
     User::unguard();
     User::create(['name' => 'admin', 'email' => '*****@*****.**', 'password' => bcrypt('123456')]);
     User::create(['name' => 'normal', 'email' => '*****@*****.**', 'password' => bcrypt('123456')]);
 }