Laravel believes jQuery sends a GET request, even if it is not.
I confirmed this with the function request()->method().
Controller function:
public function fields($vertical_id = null, $lead_id = null)
{
echo request()->method();
}
JQuery
$(document).on('change', '#vertical_id', function () {
$.post('http://myapp.local/leads/fields/1/2', $(this).closest('form').serialize(), function (data) {
console.log(data);
});
});
Route:
Route::any('leads/fields/{vertical_id?}/{lead_id?}', 'LeadController@fields')->name('leads.fields');
Notice what I had to use any, because when I tried to use post, he threw an exception that excluded the method. My console shows GETevery time I make this request.
How to get Laravel to implement jQuery sends POST, not GET?
source
share