Home > Article > Backend Development > The laravel framework uses Auth to log in asynchronously and then access other pages without login user information.
1. Use laravel's Auth verification
2. Change the model in the configuration auth.php to AppModelsAdminUser::class (because it is the login authentication of the background user)
3. Use ajax to call the background login method on the page. The main logic is as follows:
if (Auth::attempt(['name' => $request->input('name'), 'password' => $request->input('password')])) {
<code> // 认证通过... dd(Auth::user()); }</code>
At that time, I could see the dd login user information returned in the background in the browser console, but when I went to another page to print Auth::user(), it was null. What went wrong?
1. Use laravel's Auth verification
2. Change the model in the configuration auth.php to AppModelsAdminUser::class (because it is the login authentication of the background user)
3. Use ajax to call the background login method on the page. The main logic is as follows:
if (Auth::attempt(['name' => $request->input('name'), 'password' => $request->input('password')])) {
<code> // 认证通过... dd(Auth::user()); }</code>
At that time, I could see the dd login user information returned in the background in the browser console, but when I went to another page to print Auth::user(), it was null. What went wrong?