3
votes

On my Laravel website I'm using symlink to store and show the images from storage.

With

php artisan storage:link

I had created the symlink and everytime when I upload a new news article, the image is uploaded in the main Storage and with symlink it's setup to the public folder and I'm displaying the image properly.

So far so good, but when I've created a copy of the website, a problem appears...

When I've created a copy of the website with cPanels File Manager, and move to a new location, the storage symlink in the public directory has become a folder, not a symlink. After that when I try to upload a new news article, I can see it's uploaded in the main Storage folder, but not in the public/storage, so as a result the image is not displaying. That's because it's not a symlink anymore, but now it's a folder.

I've deleted the storage folder from the public directory, with SSH I've used the command again

php artisan storage:link

and I've created a new news article and the image is displaying properly, but now all other images are gone.

Is there any command that will regenerate the paths, so all other images will be display again?

I'm using Laravel 5.5

2
Comments are not for extended discussion; this conversation has been moved to chat.user3956566

2 Answers

4
votes
  1. You can solve it in another way to create a symlinkexample.php file into your public folder and run the file path into browser.
  2. Then Storage folder will be created into public folder. Folder path will be public/storage with linked to your public folder.

Code below for symlinkexample.php :

<?php
    $targetFolder = $_SERVER['DOCUMENT_ROOT'].'/storage/app/public';
    $linkFolder = $_SERVER['DOCUMENT_ROOT'].'/public/storage';
    symlink($targetFolder,$linkFolder);
    echo 'Symlink process successfully completed';
?>
3
votes

Try this:

In route/web.php add the following code:

Route::get('/storage', function(){
    \Artisan::call('storage:link');
    return "Se han vinculado las imágenes";
});