0

I am trying to display images on laravel shared hosting but I cannot get it to work.

On my local host I am using this:

      return asset("assets/avatars/avatar.png");

But on my shared hosting it does not find the image. So I have to use this:

      return asset("public/assets/avatars/avatar.png");

With adding the public. Is there any way I can make it universal so I do not have to change the code everytime I upload?

z0mbieKale
  • 969
  • 1
  • 14
  • 44

3 Answers3

0

Your Virtual Host should point to the public/ folder. If cannot do that, check this answer https://stackoverflow.com/a/28735930/2904719

Lloople
  • 1,827
  • 1
  • 17
  • 31
0

Cut all your files from public folder to root.

After cutting all of files index.php exists in root:

Replace require __DIR__.'/../bootstrap/autoload.php' with require __DIR__.'/bootstrap/autoload.php' in index.php.

Replace $app = require_once __DIR__.'/../bootstrap/app.php' with $app = require_once __DIR__.'/bootstrap/app.php' in index.php.

  • I have done that, otherwise I would not be able to run it on shared hosting. Only thing not working is my question. – z0mbieKale Oct 18 '17 at 08:12
0

You should simply create a symlink to the public folder in your shared hosting. They normally provide cPanel or Plesk, which easily allows you to do that.

Raza Mehdi
  • 923
  • 5
  • 7