Laravel + Vue:在web.php / api.php上路由

I am quite a new guy on Laravel and I have started working on a project, and I would like get some advice about the good architecture to pick.

I decided to manage my front with Vue and my backend with Laravel.

What I have started to do is to capture the routes through Laravel and sent it to my Vue routes to determines which components to load etc. And I was thinking to make "api" calls though axios into my Vue.components to retrieve the data (in JSON format) from my controller in order to display them into my view.

That's still a "web" needs.

But I am also thinking to the future API I will provide.

So what is the best option to take ?

Put some Route::resource('model', 'Controller') into the web.php file, then call those routes in my Vue.components, and put the Route::resource('model','Controller') into my api.php file ?

Thank you for your answer I don't know if I am going the right way or not.

Clément.

If you look at app\Http\Kernel.php you'll notice the distinction between the web and the api group.

  • web - process "standard" requests - they need a session, checking against a user that logged in globally in the app, processing web requests. Web UI things
  • api - process stateless API requests, will most likely always consume and return json

I usually keep the API routes in the api.php, prefix it with a version and load the controllers from the API namespace. This makes it a little more maintainable because v1 methods can be extended by a potential v2 version

Route::prefix('v1')->namespace('Api\V1')->group(function () {
    // ... API routes
});