link storage folder in laravel 8

You can link the storage folder in laravel using php artisan command and you can also run a PHP script to create a symbolic link between two folders.

Answers 2
  • Link storage folder using php script in laravel

    --PATH routes\web.php
    Route::get('/storage-link', function(){
        $target = storage_path('app/public');
        $link = public_path('/storage');
        symlink($target, $link);
        echo "symbolic link created successfully";
    })
    
    0

    You can simply use this code snippet to create a symbolic link between two folders. Sometimes you don’t have to access the terminal to run artisan commands. In that case it helps you to create a symbolic link between two folders in your laravel project. You have to simply visit the storage-link url to create a symbolic link.

  • Storage link using \Artisan::call() in web.php

    --PATH routes\web.php
    Route::get('/storage-link', function(){
        \Artisan::call('storage:link');
        dd('Storage link created!');
    });
    
    0

    This code snippet call storage:link command using php script and create storage link between storage/app/public and public/storage directory.

  • Back to code snippet queries related laravel

Related queries helps you to understand and may also used for implementation of current code snippet