jasonb's avatar

artisan storage:link question / file storage not in public

I ran php artisan storage:link and this created a link to the app/storage/public in /public/storage.

My question is when I uploaded an image it was stored in app/storage/images

and not /app/storage/public/images.

Using the store command how can I have it use the /app/storage/public as the root folder?

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

0 likes
11 replies
newbie360's avatar

without the second param disk name, default is store in local disk

so add the disk name, public is the disk name

$path = request()->file('image')->store('images', 'public');
Cronix's avatar

check the value of $post->image and make sure it's the url you think it is and it's correct. Seems like it should be /storage/images/{{$post->image}}

jasonb's avatar

The value is: images/NRrrV4jv0QX7FV5zZvQ2uAg6Cx0Brqcvpwk5S8BL.jpeg

I can see the file is there in the folder but When I try to access it via the browser its not the right path. I am not certain what I need to do.

newbie360's avatar
Level 24
  1. the image extension correct ?

  2. the image saved at storage/app/public/images/NRrrV4jv0QX7FV5zZvQ2uAg6Cx0Brqcvpwk5S8BL.jpeg ?

  3. did you make the symlink correct, put a test.jpg inside storage/app/public/ view in browser by http://your-web/storage/test.jpg

  4. make sure in your server config added Options FollowSymLinks , otherwise you can use Alias instead of symlink

# define the variable in top of the httpd.conf
Define ServerPort 8000
Define LaravelRoot <------ set the path here ------>


# add the virtual host in the bottom of the httpd.conf
<VirtualHost *:${ServerPort}>
     DocumentRoot "${LaravelRoot}/public"
     ServerName  newcrm.tc

     Alias /storage "${LaravelRoot}/storage/app/public"

     <Directory "${LaravelRoot}/public">
        #PHP_ADMIN_VALUE open_basedir "${LaravelRoot}/"
        #Options FollowSymLinks
        AllowOverride All
        Require all granted
    </Directory>
</VirtualHost>
1 like
jlrdw's avatar

If you use move when uploading instead of store with the path you want to place the image, it will make things easier.

aurawindsurfing's avatar

Have a look here:

https://laravel.com/docs/master/helpers#method-asset

I assume you do not have https enabled. Then all you should need is:

$url = asset('images/NRrrV4jv0QX7FV5zZvQ2uAg6Cx0Brqcvpwk5S8BL.jpeg');

Let us know if it works and if not what error you are getting while trying to display it. If no error is shown then look in chrome under option+CMD+I

Hope it helps!

jasonb's avatar

It was an issue with apache not being able to see the symlink. Creating an alias to /app/storage/public fixed it.

newbie360's avatar

or another option is use Accessor , so you don't need hardcoded the uri in blade

// Post model
    public function getPostImageAttribute()
    {
        return \Storage::disk('public')->url($this->attributes['image']);
    }

in blade use

<img src="{{$post->post_image}}" alt="{{$post->title}}" >
1 like
newbie360's avatar

if you want make the symlink work, just

     #Alias /storage "${LaravelRoot}/storage/app/public"

     <Directory "${LaravelRoot}/public">
        #PHP_ADMIN_VALUE open_basedir "${LaravelRoot}/"
        Options FollowSymLinks
        AllowOverride All
        Require all granted
    </Directory>
ektapuri's avatar

I am new to Laravel and I had same issue, my images are being stored at storage/app/public/images I did artisan storage:link, still my images were not accessible on browser, I updates my config/filesystems.php to use

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

Instead of

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

This fixed my issue.

Please or to participate in this conversation.