Hi everyone !
I'm stuck and i hope you could help me.
I have this ajax code :
//Html code : inside a foreach loop
<i class="far fa-times-circle deleteBoxFromModule" data-id="{{$value['pid_box']}}"></i>
//Ajax/jQuery code :
$('.deleteBoxFromModule').on('click', function(){
$.ajaxSetup({
headers: {
'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
}
});
$.ajax({
url : "/ajax/delete",
type: 'POST',
data: {_method: 'DELETE', "id" : $(this).data('id')},
success: function(msg) {
alert('Supprimé :)' + msg);
}
});
});
Then it goes to my route :
Route::delete('/ajax/delete', 'AjaxController@deleteMethod');
Then to my Controller :
use App\Api;
class AjaxController extends Controller{
public function deleteMethod(Request $request){
$api = Api('perform', 'v2');
$requeteDeleteAjax = $api->remove('box/'.$request->id);
return $requeteDeleteAjax;
}
}
The remove method is a custom made method that use the delete Guzzle method for my Lumen API.
( if you want to have a look at it ) :
public function remove($path, $content = null) {
if($content != null) {
$request = $this->api->request('DELETE', $path, ['query' => $content]);
}else {
$request = $this->api->request('DELETE', $path);
}
return $this->responseDecode($request);
}
My problem is ; The delete method isn't allowed, when i click on the delete button in my view, i have this response in the console debug in Chrome: POST http://perform/ajax/delete 500 (Internal Server Error) like if my method url was false, or bad written...
I'm stuck ...
Thanks in advance !