Gate::forUser PHP Method

forUser() public static method

Get a gate instance for the given user.
public static forUser ( Illuminate\Contracts\Auth\Authenticatable | mixed $user ) : static
$user Illuminate\Contracts\Auth\Authenticatable | mixed
return static
        public static function forUser($user)
        {
            return \Illuminate\Auth\Access\Gate::forUser($user);
        }

Usage Example

 public function testBoot()
 {
     $this->assertTrue(Gate::forUser(factory(App\User::class)->make(['is_admin' => true]))->allows('self-destruct'));
     $this->assertFalse(Gate::forUser(factory(App\User::class)->make(['is_admin' => false]))->allows('self-destruct'));
     $this->assertTrue(Gate::forUser(factory(App\User::class)->make(['is_staff' => true]))->allows('use-tags'));
     $this->assertFalse(Gate::forUser(factory(App\User::class)->make(['is_staff' => false]))->allows('use-tags'));
     $this->assertTrue(Gate::forUser(factory(App\User::class)->make(['is_staff' => true]))->allows('isStaff'));
 }
All Usage Examples Of Gate::forUser