Skip to content
Advertisement

Laravel Storage::disk(‘public_path’)->files() returning wrong path

In the following route, inspecting the image paths that this method returns, they all have “/categories/” at the start but this is not right, the actual path should be /public/images/categories/gallery/1 not /public/categories/images/categories/gallery/1

JavaScript

The following is an example of a route where it actually gets the correct paths

JavaScript

So my question is, why is it in the previous route, it returns the incorrect path with /categories/ attached to the start but not in the one above, also how do I get the correct path in the first code example posted.

I tried changing the route to Route::get('/{group:id}', function ... etc and it works but I won’t be able to use that because the url subdir will just be a number.

I also tried adding a forward slash to the path in the files() method so it was ->files('/images/categories/gallery/1'); but it still appends /categories/ to the start.

This is the config for the method in filesystems.php

JavaScript

Advertisement

Answer

The problem was not in my php but in the vue component I was using which failed to place a forward slash at the start of the src path so I changed

JavaScript

to

JavaScript

and it works.

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement