0

I have problems with the storage link in Laravel8, everything was working correctly until I moved the project from localhost to hosting, it works with public_html and I have it structured as follows.

LaravelAPP
--app
--boostrap
--config
--database
--storage
--...

public_html
--img
--storage
-- .htaccess
-- index.php
-- ... 

In localhost the public folder was inside the LaravelAPP folder but in the hosting I had to put its content in public_html.

This is the fragment of the function in which I save the documents, and it does it correctly, it saves them in the storage folder that is inside LaravelAPP but it does not do the same in public_html (I fear because it is not doing correctly the symbolic link).

$document->attach_image = $image->storeAs("public/image/$year/$user", $name_image);
$document->attach_pdf = $pdf->storeAs("public/pdf/$year/$user", $name_pdf);

When I save the image or pdf in the application I get the following URL, so it creates well the above code, but it shows me 404 | NOT FOUND because it is not created in public_html and can not show anything.

https://mydomain/storage/pdf/2022/darkvayder/pdf-test.pdf

I tried to add the following in the filesystems.php document, but it was not effective, I think the link to the public folder is still created.

'links' => [
        public_path('public_html/storage') => storage_path('app/public'),
],

1 Answers1

1

In case you're on shared hosting and have no access to the command line, you could establish the link to the public folder by using this route in your web.php:

Route::get('/linkstorage', function () { $targetFolder = base_path().'/storage/app/public'; $linkFolder = $_SERVER['DOCUMENT_ROOT'].'/storage'; symlink($targetFolder, $linkFolder); });
ouflak
  • 2,458
  • 10
  • 44
  • 49
Bervetuna
  • 31
  • 6
  • Hi, Thanks for your reply, I have tried it and when I enter /linkstorage I get 500 Server Error. Should that happen? – Alex Toledo Jan 13 '22 at 10:16
  • Thanks, mate. It worked for me. Basically, it created a folder called storage outside of the project folder. Then I can call my images from there via the browser. – Crane Nov 10 '22 at 15:18