I have the following piece of code in Laravel BaseController. I want to protect all my api resources with an Authorization
header with a token.
pu
You cannot have two returns in PHP:
return Request::header();
return Response::json();
So in your code, only the header will return, and your code will exit.
I think this will work
return Response::json(['error'=>'Not authorized. Access token needed in Header.Authorization'], 403)->header('Authorization');
If not - this definetely will:
$response = Response::json(['error'=>'Not authorized. Access token needed in Header.Authorization'], 403);
$response->header('Authorization');
return $response;