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
It is a Laravel & Apache problem, this line in public/.htaccess fixed it for me:
RewriteRule ^ - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
The fix is from https://github.com/dingo/api/issues/54
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;