Trying to delete uploaded images via ajax post request on post edit form. But i am facing some issues, when i press on delete button - it successfully sends ajax post request with image path, then in my controller i am trying to delete that file, but it not deleting it.
Here's my js:
(function($) {
$('.del-image').click(function() {
var thisUrl = $('.col-md-10 img').attr('src');
$.ajax({
method: 'post',
url: '/del-image',
data: {imgUrl: thisUrl, id: pageId},
error: function(e) {
alert('Error' + e);
}
});
});
})(jQuery);
Then in controller i am receiving ajax post request:
public function deleteImage() {
if (Request::ajax()) {
$path = Input::get('imgUrl');
File::delete($path);
return 'ajax request';
}
return App::abort(404);
}
And in routes.php i have:
Route::any('del-image', array('uses' => 'PageController@deleteImage'));
Any help would be appreciated!
AJAXrequest is being sent to your controller and what you get instead, any error messages ? Where your files are saved (in the public folder) ?try{ File::delete($path); return 'ajax request'; } catch(Exception $e) { dd($e); }pathis right and haswritepermission.successmethod in yourAJAXcall, how do you see'ajax request'in theconsole.