Search code examples
phplaravellaravel-storage

Laravel storage public url after storage:link not working


I'm trying to access the public images on my server via URL on the browser.

To do this, I have the following hierarchy in my storage folder:

storage
   |app
     |public
        |post
           |1
             |myimage.png

I then ran the following command to create a link

php artisan storage:link

Now when I try access my image on the browser via http://localhost:8000/storage/post/1/myimage.png I get a 404 NOT FOUND page.

I even tried http://localhost:8000/post/1/myimage.png, same thing.

Here are my settings in my filesystems.php file:

'disks' => [
    ...,
    'public' => [
        'driver' => 'local',
        'root' => storage_path('app/public'),
        'url' => env('APP_URL').'/storage',
        'visibility' => 'public',
    ],
    ...,
],

'links' => [
    public_path('storage') => storage_path('app/public'),
],

Am I doing this all wrong?


Solution

  • I have found a solution to my public images dilemma.

    I'm no longer storing images in /storage/public and creating a symbolic link, but in the /public folder from root directly.

    I had to add a configuration in the /config/filesystems.php file like so:

    'disks' => [
        ...,
        'root_public' => [
            'driver' => 'local',
            'root' => public_path('/'),
            'url' => env('APP_URL'),
            'visibility' => 'public',
        ],
        ...,
    ],
    

    With this, my public directories and images are accessed via http://localhost:8000/mypublicpath/myimage.png