从存储中删除文件后删除行

Delete the row after removing file from storage

一切正常,但抛出错误“Trying to get 属性 non-object 的‘路径’”在此行 “unlink(“uploads/”.$img->path);” 当我刷新行和文件时 已删除。如果有其他方法请告诉我

blade :

<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>

  &nbsp;&nbsp;

  <a href="#"><i class="fa fa-trash" style='color:red;'    wire:click="selectItem({{ $img->id }}, 'delete')"  data-target="#modalFormDelete"></i></a>

  </td>

    @endforeach

</tr>



       
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);//bug here
        Caroussel_Img::where("id",$img->id)->delete();
        $this->dispatchBrowserEvent('closeDeleteModal');
     }

这不是个好主意, 我不知道里面是什么“Caroussel_Img”

但如果它正在删除文件,请在行首添加“@”,它不会再打扰您了

@unlink("uploads/".$img->path);