In my opinion, creating an Api folder and separate namespace for api controllers is a better solution, if your website and mobile application will meet different requirements, so write them in a same controller is a bad idea. I guess you care your website's seo.
Mar 27, 2017
2
Level 2
Best Practice To Manage Laravel 5.4 API With Existing Web
Hi Awesome People
I'm working on an e-commerce project using laravel-vue for website and laravel-api for mobile application, i wanted suggestion on the best way to manage api part or the best way to implement the project
these are my thoughts on implementing this
1->using same controller for both api and web, but worried abut complex logic and scalability
public function index(Request $request)
{
$users = User::all();
if ($request->wantsJson()) {
//return json-data for mobile app
}
return view('agents', compact('users'));
}
2->creating separate namespace for api controllers. namespace App\Http\Controllers\Api\;
3->creating just the api using laravel and create client app using vue-cli/angular2 so that the mobile app and web app can use the same api. here concerned about SEO
any suggestions are welcome
thank you
Please or to participate in this conversation.