You can check this on the request:
if ($request->wantsJson()) {
// output json
}
if ($request->isJon()) {
// input is json
}
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
Hello, I'm working in a application where I'm using same API for desktop and android app in order to reuse the code. For an example There is an create user form in desktop website as well as in the app. So I have written one API to submit the form data, which is working perfectly. But my main requirement is to get the origin request for that form submit/post API. I have tried
jenssegers/agent package
, so far I am able to detect weather its mobile or desktop. Is there any other way to detect that the post request coming from the app end?
An extra parameter will do the job for sure, but I would like to avoid it. Any help is appreciated.
@dutchman1990 Does your app use different headers or authorization token at all? If it does, you can make a helper function to check the headers for a key. Our app sends Authorization header (for passport) while our web end uses the passport web cookie in the web session, so I just lookout for the Authorization key to know it is app:
if(request()->hasHeader('Authorization')){
//is from app
}
Please or to participate in this conversation.