If yes, How do you do it ?
I like to create an Api folder inside my app folder, where I have a V1 folder and inside it, I have a Controllers folder where I keep all of my JSON responses. Same goes with the routes, I put them into a separate routes file in Api/V1.
I wanna keep them separate because I don't wanna clutter the controllers which return views with additional if checks. It's gonna be easier for building APIs later on.
Usually not. But I tend to make controllers RESTful minded. So if I have Group and Users, I don't make a method called Users in GroupController, but I make a subfolder called Group and there I create UsersController where I can have /groups/{id}/users. That's how I'm structuring my controllers.
Mev-Rael
Executive Product Leader & Mentor for High-End Influencers and Brands @ mevrael.com
The best thing about Laravel is it allows you easy handle ajax requests and return model in JSON format. For typical cases I have ajax requests in same controller:
if ($Request->ajax()) { return $model; } else { return view(..., ['model' => $model]); }However, for APIs you need a different namespace, base API/REST controller and separate controller for each module/domain. For example, I can have
app/Http/Controllers/UsersControllerandapp/Http/Controllers/Api/UsersControllerand different routes file for it with group, namespace and middleware for APis.