The
auth
function returns an authenticator instance. You may use it as an alternative to the Auth
facade:<?php $user = auth()->user();
<?php $user->wasRecentlyCreated = false;
}
auth()->guard($driver)->setUser($user);
auth()->shouldUse($driver);
}
<?php auth()->guard($driver)->setUser($user);
auth()->shouldUse($driver);
}
function id() {
<?php protected function defineRoutes($router)
{
$router->post('logout', function (Request $request) {
auth()->logoutOtherDevices($request->input('password'));
return response()->noContent();
})->middleware(['web', 'auth']);
<?php {
public function protect()
{
if (auth()->check()) {
return;
}
<?php public function current(): ?User
{
if (! $user = auth()->user()) {
return null;
}
<?php public function logout()
{
auth()->logout();
abort(redirect($this->params->get('redirect', '/'), $this->params->get('response', 302)));
}
<?php public function all()
{
if (auth()->guest()) {
return [];
}
<?php 'response_code' => 200,
'logged_in' => $loggedIn = auth()->check(),
'logged_out' => ! $loggedIn,
<?php ])
->assertLocation('/');
$this->assertFalse(auth()->check());
$output = $this->tag(<<<'EOT'
{{ user:login_form }}
<?php public function it_will_log_user_in_and_render_success()
{
$this->assertFalse(auth()->check());
User::make()
->email('san@holo.com')
<?php ])
->assertLocation('/');
$this->assertTrue(auth()->check());
$output = $this->tag(<<<'EOT'
{{ user:login_form }}
<?php public function it_will_log_user_in_and_follow_custom_redirect_with_success()
{
$this->assertFalse(auth()->check());
User::make()
->email('san@holo.com')
<?php ])
->assertLocation('/login-successful');
$this->assertTrue(auth()->check());
$output = $this->tag(<<<'EOT'
{{ user:login_form }}
<?php public function it_wont_log_user_in_and_follow_custom_error_redirect_with_errors()
{
$this->assertFalse(auth()->check());
User::make()
->email('san@holo.com')
<?php ])
->assertLocation('/login-error');
$this->assertFalse(auth()->check());
$output = $this->tag(<<<'EOT'
{{ user:login_form }}