Back

How to get current user in laravel passport?


I am using Laravel 5.4 and API Authentication Passpot and dingo API.

My Route:

$api->group( [ 'prefix' => 'account' ], function ( $api ) {
            $api->post( 'login', '[email protected]' );

and My UserController is:

public function login( Request $request ) {

        if(!Auth::check()) {
            $validator = Validator::make(
                $request->all(), [
                    'email'    => 'required|email|exists:users,email',
                    'password' => 'required|min:6'
                ]
            );
            if ( $validator->fails() ) {
                throw new StoreResourceFailedException( trans( 'messages.api.login' ), $validator->errors() );
            }...

I want to be logged on if the user is not authenticated but

Auth::check()

Alwayes return null ?

It should be noted that when I add

->middleware( 'auth:api' )

to my routes it gets true:

$api->post( 'login', '[email protected]' )->middleware( 'auth:api' );

How can I fix this problem?


Sign in to participate in this thread!



We'd like to thank these amazing companies for supporting us