I am using laravel 5.4 in my project i displayed my images inside source file in laravel blade it shows the image correctly..
<div id="dis_img">
@foreach($detail_dir_imgs as $detail_dir_img)
<img src="{{ asset($detail_dir_img) }}" height="230" width="200" id="pro_img">
<span class="del_proimg">X</span>
@endforeach
</div>
Now i get the image src attribute inside the del_proimg click function which means i want to delete the image when i click this id and the code inside my click function is
$('.del_proimg').click(function(){
var img= $('#pro_img').attr("src");
alert(img);
$.ajax({
type: "GET",
url: '/deleteimg',
data: {'img':img},
success: function(data){
console.log("ajaxdata",data);
},
error: function(jqXHR, textStatus, errorThrown) {
console.log(JSON.stringify(jqXHR));
console.log("AJAX error: " + textStatus + ' : ' + errorThrown);
}
});
});
When the id is clicked it get the imagepath and pass the data to controller everything worked fine but in my controller when i try to delete the image path it doesnot delete the image and my controller code is
public function deleteimg(Request $request){
$img =$request->img;
@unlink(public_path( $img));
return Response::json([
'message' => $request->img
], 200);
}
Is this is correct i tried this also File::delete($img) but its not delete my image in my folder but no error shows please anyone help me to fix this isssue