MrRobot21's avatar

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

0 likes
2 replies
hxd's avatar

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.

1 like
MrRobot21's avatar

@BradHe thank you for your time

yes since it is a e-commerce website SEO is a major concern if i'm building the client app in Vue-lci or Angular-cli

i would really like to is there any way to do server side rendering of Vue 2 when using Laravel Api

and i like you suggestion about creating different namespace for controller

thank you

Please or to participate in this conversation.