Anyone?
Why is it bad idea to use Request::isJson instead of API route?
Hi,
Can someone explain to me in a nutshell why I should not be doing this in my existing laravel app?
I want to add json responses to use it in a native app. I have working controllers, routes etc.
Now not to rewrite the whole logic I figured that for a simple usage I can do just this:
if (\Request::isJson()) {
return \Response::json(compact('articles', 'categories', 'colors', 'id'));
} else {
return view('homepage', compact('articles', 'categories', 'colors', 'id'));
}
and get a nice json response that I will be using inside my iOS android app.
I have a feeling however that apart from obvious pagination, authentication and etc there is a much more to it.
What am I doing wrong please?
API routes are segregated because it is expected to use different authentication methods and to not use session management.
If you want to use sessions then I would stick with web.php and if you want to use passport or token authentication (stateless requests) then use api.php
At least thats the way I understand it
Please or to participate in this conversation.