Home > Backend Development > PHP Tutorial > 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
Release: 2016-09-02 08:57:05
Original
1300 people have browsed it

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>
Copy after login
Copy after login

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>
Copy after login
Copy after login

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?

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template