InToSSH
7 months ago
54
3
Vue

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

Posted 7 months ago by InToSSH

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.

Please sign in or create an account to participate in this conversation.