League\Flysystem\Filesystem::delete(): 参数 #1 ($location) 必须是字符串类型,给定为空,调用

League\Flysystem\Filesystem::delete(): Argument #1 ($location) must be of type string, null given, called in

我无法编辑照片

php 版本 8.1.4

laravel 9.14.1

更新功能:

 public function update(Request $request, Category $category)
{
    $request->validate([
        'name' => 'required',
        'description' => 'required'
    ]);

    $image = $category->image;
    if ($request->hasFile('image')) {
        Storage::delete($category->$image);
        $image = $request->file('image')->store('public/categories');
    }
    $category->update([
        'name' => $request->name,
        'description' => $request->description,
        'image' => $image
    ]);

    return to_route('admin.categories.index');
}

错误:

League\Flysystem\Filesystem::delete():参数 #1 ($location) 必须是字符串类型,给定为空,在第 481 行的 C:\Users\sedat\Desktop\newproject\vendor\laravel\framework\src\Illuminate\Filesystem\FilesystemAdapter.php 中调用

你可以试试:

!is_null($category->image) && Storage::delete($category->image);