Answer the question
In order to leave comments, you need to log in
Where is the right place to send AJAX requests in Laravel?
I worked on a project, we created an api folder, created a php file in it that will process an AJAX request and return a response from there.
What is the correct way to do this in Laravel? In the view, write JS that will send an AJAX request, and there are the following options:
Answer the question
In order to leave comments, you need to log in
In the routes/api.php folder, add your routes,
and you can put the controllers that will process them in app/http/controllers/api/*
Why put all ajax methods or routes in one place? If you want to request something from the users table via ajax, then create a method in UserController. In the method, you can specify, for exampleif (!$request->ajax()) return abort(403);
Laravel and php does not matter AJAX is a request or not, the principle of operation is exactly the same. Just create a route and a controller method for a specific request. If you need to somehow process all ajax calls in the same way, then there is a middleware for this.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question