Logging a User In Without Sessions or Cookies

Problem

You want to log a user in without using cookies or the session.

Solution

Use the Auth::once() method.

This method takes an array containing the user's credentials.

$logged_in = Auth::once(['username' => 'test', 'password' => 'test']);
if ( ! $logged_in)
{
    throw new Exception('not logged in');
}

Discussion

The user will remain "logged in" only for the current request.

This is a handy method to use when testing.

comments powered by Disqus