I'm trying to send data with ajax (using axios for that) through an api to my controller.
First of all my routes file (/routes/api.php):
Route::post('/booking/request', 'BookingController@sendMail');
I want to send data to this route, so here is my request for that:
var bookingUrl = baseUrl + 'api/booking/request';
axios.post(bookingUrl, {
name: "username",
amount: 2
});
And after that, I just want to log this data to see if it got to my controller (app/Http/Controllers/BookingController):
class BookingController extends Controller
{
public function sendMail(Request $request)
{
Log::info('data: ' . $request->name);
}
}
This doesn't work at all. I just get an error "404 Not Found". I also tried this request with Postman, but same results. Since I can't get more information about what exactly isn't working, I can't fix it. Can someone get me on the right path here?
Edit: So the actual problem was the baseUrl. There was a wrong link behind, so it couldn't work.
bookingUrl
set to? Checkphp artisan routes:list
to make sure it matches. - aynberbaseUrl + 'api/booking/request'
. And php artisan routes:list is showing an entry for my routePOST | api/booking/request | App\Http\Controllers\BookingController@sendMail | api
- kk_public function sendMail(Request $request)
for the definition, and insideLog::info($request->name);
- aynber