everything works perfectly but it throw an error “Trying to get property ‘path’ of non-object”
blade on this line “unlink(“uploads/”.$img->path);” and when I refresh the row and file are deleted
<table class="table table-hover">
<thead>
<tr>
<th scope="col">image</th>
<th scope="col">title</th>
<th scope="col">Actions </th>
</tr>
</thead>
<tbody
>@foreach($data as $img)
<tr>
<th scope="row"> <img src="uploads/{{ $img->path }}" width="50%" /></th>
<td>{{$img->title}}</td>
<td>
<a href='#'><i class="fa fa-edit" id="updateIcon" wire:click="selectItem({{ $img->id }}, 'update')" ></i></a>
<a href="#"><i class="fa fa-trash" style='color:red;' wire:click="selectItem({{ $img->id }}, 'delete')" data-target="#modalFormDelete"></i></a>
</td>
@endforeach
</tr>
<div class="modal fade" id="modalFormDelete" tabindex="-1" aria-labelledby="modalFormDeletePost" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="modalFormDeletePost">Delete Item</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<h3>Are you sur ?</h3>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Cancel</button>
<button wire:click="delete" type="button" class="btn btn-danger"><i class="fa fa-trash" style='color:white;' aria-hidden="true" ></i> Yes</button>
</div>
</div>
</div>
</div>
<div>
</tbody>
class :
public function selectItem($itemId, $action)
{
$this->selectedItem = $itemId;
if ($action == 'delete') {
$this->dispatchBrowserEvent('openDeleteModal');
}
}
public function delete()
{
$img=Caroussel_Img::find($this->selectedItem);
unlink("uploads/".$img->path);
Caroussel_Img::where("id",$img->id)->delete();
$this->dispatchBrowserEvent('closeDeleteModal');
}