Level 104
$request->wantsJson() will inform you if the request has application/json header.
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
I have a project which has API users and Session users
I use FormRequest objects fro validation and these automatically detect if the request is a session or API request and return JSON for api requests and redirects for Session requests
Is there any way i can make this distinction in my controllers?
I have a controller which can serve both API and Session users - one needs a JSON response the other needs a redirect
$request->wantsJson() will inform you if the request has application/json header.
Please or to participate in this conversation.