@vincent15000
I know all of that, that's not my problem
my question is how there auth()->user() returns object of user after Auth::attempt() Although there's no token in request yet, how the app know the authenticated user without any tokens?
@MohamedKamal "Although there's no token in request yet, how the app know the authenticated user without any tokens" since you attempted to auth the user via email and password, inside this request the user will be authenticated. The token is than used to authenticate the user on other api routes, since there is no session to authenticate the user for you.
@MohamedKamal The ->createToken() function is used for other situations.
For example if you create an API to provide some datas, but without any frontend and if you want to share these datas with other developers so that they can use them, you can use this function in order that the users create a token. Then they can use this token inside their own backend or frontend to retrieve the datas you provide.