0
votes

I have a form with a file input ready to be saved.

 $request->validate([
            'name'=> 'required|min:3',
            'image'=> 'required|image|mimes:jpeg,png,jpg'
        ]);

        $category = new Category();
        $category->name = $request->name;

        $path = $request->file('image')->store('categories_images');

        $category->image = $path;

What the above code does is that it grabs the image field from the request and save it to the categories_images folder. When I first uploaded a file to test it it created the folder in storage/app.

My problem is that I want to preview the images on my site:

//store.state.serverPath returns: http://localhost:8000 -> this is right
<img :src="`${$store.state.serverPath}/storage/${category.image}`" class="image-wd"/>
 

When I inspect it in the nrowser it says:

http://localhost:8000/storage/categories_images/adGR57Gq6lNUqRVvEubRDfxNMZzEhya3A7oESUox.png not found

It expects the images in storage/app/public but creates the categories_images folder everytime I upload an image in storage/app. Am I missing something here?

2

2 Answers

0
votes

It seems I can't post a comment just as an answer. So let me add my input. Did you create your symbolic link? If not do it now, or just redo it. I had the same issue when i ported my code from mac to windows. Even if all the configuration was done corectly the link was related to my mac. I just fixed that issue now for my code. So thank you for your question.

   php artisan storage:link

Also the first parameter of store is the path you want to save the file under storage/public directory. You need to append the directory name in yor url to find the file. This is the code I use in one of my projects.

$path = isset($validated['document']) ? $path = $request->file('document')->store('pdfs', 'public') : null;

The file will be accessed with the url www.example.com/storage/pdfs/$path

document is the name of file input.

0
votes

You miss the part of the tutorial where he changed the config -> filesystems.php with this

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