Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

megaman7's avatar

API vs Session

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

0 likes
1 reply
tykus's avatar
tykus
Best Answer
Level 104

$request->wantsJson() will inform you if the request has application/json header.

Please or to participate in this conversation.