user14112985
user14112985

Reputation:

Get authenticated User in API controller in Laravel

I want to fetch the Authenticated User's data in API controller. How to do that?
Here is my API\CompanyController

public function selected_company(){
        return Auth::user()->id;
    }

The error I got through HTTP request... Error Image Here

Upvotes: 1

Views: 745

Answers (1)

linktoahref
linktoahref

Reputation: 7992

To convey the comment in a comprehensible manner,

Either your controller should have a middleware, like

public function __construct()
{
    $this->middleware('auth:api');
}

Or your route to the api should be passed through the middleware

Route::get('your-api-endpoint')->middleware('auth:api');

Upvotes: 1

Related Questions