Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

php
laravel
communitycreator

How to fix storage link not working issue in Laravel

henry anorue

Laravel is a framework built in PHP. It is an open-source programming language that has been at the forefront of the most popular backend languages ​​for many years. Laravel itself has many features and tools that make programming efficient and trouble-free.

Laravel follows the model-view-controller design pattern (MVC). Laravel reuses existing components of various frameworks. This is useful to build web applications. Web applications designed in this way are more structured and practical.

File storage

Laravel provides a powerful file system abstraction with the Flysystem PHP package. Laravel Flysystem integration provides a simple driver for working with local file systems, SFTPSSH File Transfer Protocol, and Amazon S3. It is surprisingly easy to switch between these storage options between your local development computer and your production server, as the API remains the same for every system.

Configuration

Laravel’s file system configuration files are located in config / filesystems.php. This file allows you to configure the disks of any file system. Each disk represents a specific storage driver and location.

The local driver interacts with files stored locally on the server running the Laravel application while the S3 driver is used to write to Amazon’s S3 cloud storage service.

Create a symbolic link

By default, public disks use local drivers and store these files under storage/app/public. To access them via the web, you need to create a symbolic link from public/storage to storage/app/public.

  1. Go into the .env file, create a variable called FILESYSTEM_DRIVER, and set it to public, as shown below:
FILESYSTEM_DRIVER=public

Next, use the command below in order to create the symbolic link.

php artisan storage:link
  1. Alternatively, you can also try fixing the issue without the need for SSH to the server. For Laravel 5 and above, you can use the Artisan :: call() method on the route or controller to execute Artisan commands without using a terminal. First, go to the route folder your-app-folder/routes/web.php and register a new route as follows.
Route::get('/linkstorage', function () {
    Artisan::call('storage:link');
});

Then, when you go to your website, you get a blank page. A storage folder is created.

  1. You can also go to the public directory and run:
rm storage

Then go to the project root and run:

php artisan storage:link
  1. This can also be solved by doing a modification on the filesystems config/file systems from:
'local' => [
            'driver' => 'local',
            'root' => storage_path('app'),
        ]

to:

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

RELATED TAGS

php
laravel
communitycreator
RELATED COURSES

View all Courses

Keep Exploring