6 months ago

How to structure Controller for AJAX and CRUD endpoints?

Posted 6 months ago by chadhutchins

We have a pretty standard Laravel app. I have the usual CRUD endpoints for the for dealing with my models, but I also need to add some AJAX calls.

Say I have a CarsController. Is it pretty typical to have my CRUD endpoints there AND any of the AJAX call endpoints I would need? Or is it better organized to have those in two different Controllers?

Similarly, I have an endpoint to list all Cars and it spits out a view with a nice table to show me all of my Cars. I need to have an AJAX endpoint that gives me an array of all cars in JSON but not render a view. Should this call a single Controller endpoint (as they do the same thing except the render part) or should it be split into to Controller methods?


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