I've extended the Illuminate\Http\Request
class and am passing it along to my controller.
In my controller, I check if the request has an Accept: application/json
header, using the $request->wantsJson()
method.
If I use the base Illuminate\Http\Request
class it works perfectly fine, but if I use my extended class, it says that the Accept header is null.
use Illuminate\Http\Request;
class MyRequest extends Request
{
...
}
Controller
class MyController
{
public function search(MyRequest $request) {
if ($request->wantsJson()) {
// return json
}
// return view
}
}
This does not work. If I instead replace MyRequest
with an instance of Illuminate\Http\Request
it works. If I var_dump $request->header('Accept')
, it's NULL when using MyRequest.