Home  >  Article  >  Backend Development  >  The laravel framework uses Auth to log in asynchronously and then access other pages without login user information.

The laravel framework uses Auth to log in asynchronously and then access other pages without login user information.

WBOY
WBOYOriginal
2016-09-02 08:57:051270browse

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?

Reply content:

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?

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn