1

I am trying to upload a file to a public folder which was working lately but now it is showing below error:

Disk [public] does not have a configured driver.

I tried checking for configured driver in config/filesystems.php but, it is already set there. I am not getting where the issue might be.

Upload code:

public function upload(ProductImageRequest $request, Product $product)
{
    $image = $request->file('file');
    $dbPath = $image->storePublicly('uploads/catalog/'.$product->id, 'public');

    if ($product->images === null || $product->images->count() === 0) {
        $imageModel = $product->images()->create(
            ['path' => $dbPath,
            'is_main_image' => 1, ]
        );
    } else {
        $imageModel = $product->images()->create(['path' => $dbPath]);
    }

    return response()->json(['image' => $imageModel]);
}

Code in config/filesystems.php

'disks' => [

        'local' => [
            'driver' => 'local',
            'root' => storage_path('app'),
        ],

        'public' => [
            'driver' => 'local',
            'root' => storage_path('app/public'),
            'url' => env('APP_URL').'/storage',
            'visibility' => 'public',
        ],
β.εηοιτ.βε
  • 33,893
  • 13
  • 69
  • 83

1 Answers1

1

i use this code for moving the picture and storing its name you may want to give it a shot

//get icon path and moving it
$iconName = time().'.'.request()->icon->getClientOriginalExtension();
$icon_path = '/category/icon/'.$iconName;
request()->icon->move(public_path('/category/icon/'), $iconName);  
$category->icon = $icon_path;

i usually move the image then store its path in db and this is what my code shows you can edit it as desired

RYOK
  • 473
  • 7
  • 23