In my laravel app request header value returns an expected value on my localhost. but when i upload project on server its returning null value. I created a middleware Authkey.php
public function handle(Request $request, Closure $next)
{
$token = $request->header('API_ACCESS_KEY');
dd($token);
if ($token !=env('API_ACCESS_KEY')) {
return response()->json(['message' => 'Unauthorized'],401);
}
return $next($request);
}
2
Answers
Replace the
API_ACCESS_KEY
in your request withApi-Access-Key
, also update it at your middleware too ,as the underscores are invalid characters for header names,
for more info please check apache new features