Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How laravel `Auth:user()` or `Auth:id()` works

How laravel Auth:user() or Auth:id() works

Is it resides in session or database.

I searched but not get good article.

Please help to understand. I know I will get many down-votes ;)

like image 912
GRESPL Nagpur Avatar asked Feb 27 '17 13:02

GRESPL Nagpur


People also ask

What is the difference between auth () user () ID and Auth () ID?

Difference between auth()->user()->id and Auth::user()->id. Short explanation: No difference really, they both return an instance of Illuminate\Auth\AuthManager . So Auth:: and auth() in your examples will be the exact same object.

How does Laravel Auth attempt work?

The attempt method accepts an array of key / value pairs as its first argument. The password value will be hashed. The other values in the array will be used to find the user in your database table. So, in the example above, the user will be retrieved by the value of the email column.

What is auth ()- user () in Laravel?

Auth::user() — You can check if a user is authenticated or not via this method from the Auth Facade. It returns true if a user is logged-in and false if a user is not. Check here for more about how Facades work in Laravel.

How does Laravel default authentication work?

Laravel includes built-in authentication and session services which are typically accessed via the Auth and Session facades. These features provide cookie-based authentication for requests that are initiated from web browsers. They provide methods that allow you to verify a user's credentials and authenticate the user.


2 Answers

You can find this method in Auth\SessionGuard class :

Authenticatable|null user()

Get the currently authenticated user.

Return Value Authenticatable|null

Check it out: https://laravel.com/api/5.7/Illuminate/Auth/SessionGuard.html#method_user

like image 163
A.Essam Avatar answered Nov 01 '22 23:11

A.Essam


Did you read this? Its a good guide to start with

https://laravel.com/docs/5.4/authentication

like image 25
pascal zoet Avatar answered Nov 02 '22 01:11

pascal zoet