Laravel - Requests - Request Headers

You may retrieve a request header from the Illuminate\Http\Request instance using the header method. If the header is not present on the request, null will be returned. However, the header method accepts an optional second argument that will be returned if the header is not present on the request:

    
    $value = $request->header('X-Header-Name');
    
    $value = $request->header('X-Header-Name', 'default');
	

The hasHeader method may be used to determine if the request contains a given header:

    
    if ($request->hasHeader('X-Header-Name')) {
        //
    }
	

For convenience, the bearerToken method may be used to retrieve a bearer token from the Authorization header. If no such header is present, an empty string will be returned:

    
    $token = $request->bearerToken();