public function test_it_has_relations() { $role = Role::create(['name' => 'Foo', 'slug' => 'foo']); $this->assertTrue($role->users instanceof Collection); $this->assertTrue($role->users() instanceof BelongsToMany); $this->assertTrue($role->permissions instanceof Collection); $this->assertTrue($role->permissions() instanceof BelongsToMany); }
public function test_it_can_check_permission_through_role() { $user = $this->createUser(); $this->assertFalse($user->hasPermissionTo('create-post')); $permission = Permission::create(['name' => 'Create post', 'slug' => 'create-post']); $role = Role::create(['name' => 'Author', 'slug' => 'author']); $role->permissions()->attach($permission); $user->roles()->attach($role); $user->refreshPermissions(); $this->assertTrue($user->hasPermissionTo('create-post'), 'user cannot create post'); }
/** * @param string $slug * * @return Role */ protected function findRole(string $slug) { return Role::where('slug', $slug)->first(); }