Home  >  Article  >  Backend Development  >  Laravel implements simulated user login

Laravel implements simulated user login

小云云
小云云Original
2018-03-27 11:43:122275browse

This article mainly shares with you Laravel to implement simulated user login, hoping to help everyone.

//强制用户id位100的人登录Auth::loginUsingId(100);//获取这个登录用户的id;dd(auth()->user()->id);

During testing, I need to test the relevant information of a certain logged-in user. We can force login in the auth provider. In this case, there is no need to write a loginUsingId in a specific method. .

app\Providers\AuthServiceProvider.php

Add the user you want to log in to the boot, then the user will be logged in globally.

    public function boot()
    {
        auth()->loginUsingId(348);        $this->registerPolicies();
    }

After the test is completed, just remove that line. If you want to log in somewhere In this method, temporarily change the user login, then use loginUsingId again.

Related recommendations:

Code to use curl to simulate user login under PHP_PHP tutorial

The above is the detailed content of Laravel implements simulated user login. For more information, please follow other related articles on the PHP Chinese website!

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