Is it possible to make guests automatically associate with any user from the database. For example, now if $request->user() executed in the controller, this method will return NULL . I would like to return a user model instance instead of NULL. Perhaps this will be an instance of the App \ User model with id == 0. I need this because I want to assign roles and privileges to the guest using the module https://github.com/Zizaco/entrust .

    1 answer 1

    if (Auth :: check ()) {} // User is authenticated However, you can also use middleware to verify user authentication before accessing specific routs / controllers. http://laravel.su/docs/5.1/authentication#authenticating-users

    $ email, 'password' => $ password])) {// Authentication was successful return redirect () -> intended ('dashboard'); }}}

    And here's another

    User ID Authentication To authenticate a user by their ID, you can use the loginUsingId method. This method takes the user ID as an argument:

    Auth :: loginUsingId (1); User authentication per request You can also use the once method to authenticate a user in your application per request. No session, no cookies will be created, which can be used to create a stateless API. The once method works on the same principle as the attempt:

    if (Auth :: once ($ credentials)) {//}

    This is all from the documentation on Laravel.su and laravel.ru

    But it is better to read English laravel.com/docs

    On the first link all this is available in a more readable form.

    By reauthorization: When a guest wants to login, use your own handler. In processing, first Auth :: logout (); and then your authorization.