Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

intossh@gmail.com's avatar

Best practices: Vue.js -> Laravel AJAX API resources

Hi, I am currently trying to learn Vue.js and I would just like to ask you for your opinion / best practices / how do you do it, when I need to fetch some data from Laravel.

For example I want to populate a Products table in Vue component, so I make an AJAX request using Axios, but now how do you handle it on the Laravel side? I would like to have the routes separate from the normal request routes (not using Vue-router), so only the data will be fetched using Axios.

Do you use a Resource (make:resource) to get the data and normal controller to edit/store them? Do you create a separate Resource controller (make:controller --resource) in App\Http\Controllers\Api for API calls ? Do you mix them together with normal routes (also for serving blade views for pages)? Or do you have a different approach?

I know that when I create a resource controller I have all the methods for GET requests to show the page (using Blade view) as well as POST/PUT requests which I can call from Axios to store the changes, but I don't quite like the idea of having all of them together.

Thanks for any ideas.

0 likes
3 replies
NoTimeForCaution's avatar

I prefer to adhere to RESTful convention as much as possible, even with Axios API calls.

I have, however, also used dedicated API resource routes and route namespace for data interaction between Vue and Laravel.

php artisan make:controller API/PostsController --api
Route::namespace('Axios')->group(function () {
    // Controllers Within The "App\Http\Controllers\Axios" Namespace
});

I'd simply recommend maintaining a workflow that is consistent with the same practices you use in Laravel. I don't like "switching gears" just because I'm interacting with Vue. I just want to be consistent.

gorakhyadav's avatar

Try with this

 https://blog.pusher.com/web-application-laravel-vue-part-5/
intossh@gmail.com's avatar

Thanks for the answers guys. That's a nice tutorial there @gorakhyadav . I think I will stick to the single Resource controller with it's routes as it will be faster to specify in the routes file and I would need those routes anyway. I just always had in mind that API/AJAX calls should be somewhere separate, but at the end of the day they still serve the same purpose in a single controller.

Please or to participate in this conversation.