How to access storage in Laravel

Laravel

How to access storage in Laravel

Laravel uses a public disk for files and images that should be publicly available. The default public disk uses the local driver and all files are stored in storage/app/public.

However, the storage folder is not publicly accessible from the web browser and because of that, we will have to create a symbolic link from public/storage to storage/app/public.

You can look at a symbolic link as a pointer to a file or as a desktop shortcut to an executable located somewhere on a hard drive. If we edit, add, delete something from the storage it will reflect actions to the symlinked folder.

It is useful to create symlinks when accessing the same files from multiple locations such as pdf files, user-uploaded images, and etc.

In Laravel, we create symlink by running the following artisan command

php artisan storage:link


Once we have the symlink created we can generate an url to a file with Laravel asset() helper

asset('storage/images/avatar.jpg');


To generate a src for our image tag

<img src="{{ asset('storage/images/avatar.jpg') }}" alt="User avatar image" class="avatar">

Show comments

Laravel

5 min

How to make Laravel authentication

Laravel provides a neat function that quickly generates a scaffold of routes, views, and controllers used for authentication.

Laravel

7 min

How to install Laravel application

This article will cover how to install and create a local development environment for your Laravel application. There are only a couple of steps that needs to be done.

Laravel

3 min

How to set appropriate Laravel permissions on Linux server

After publishing your Laravel application to a real web server, you discover then some of your functionalities are failing.

Codinary