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

Time:05-27

i can't edit photo

php version 8.1.4

laravel 9.14.1

update function :

 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');
}

error :

League\Flysystem\Filesystem::delete(): Argument #1 ($location) must be of type string, null given, called in C:\Users\sedat\Desktop\newproject\vendor\laravel\framework\src\Illuminate\Filesystem\FilesystemAdapter.php on line 481

CodePudding user response:

You can try:

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