Images in app/public (laravel) not show in Heroku app

Viewed 8070

I have a project in laravel which one of the sections upload images to the server. Images are saved by using File storage and in the / storage / app / public folder. In local works correctly, the images look good, but when I upload the project to heroku, the images are not seen. Even in heroku run the command "php artisan storage: link"

Why can not I see the images? I would not want to use AWS S3 for this. What could I miss?

Thank you..

6 Answers

In your composer.json add:

"post-install-cmd": [ "ln -sr storage/app/public public/storage" ],

What I did that worked for me:

In your composer.json add:

"post-install-cmd": [ "ln -sr storage/app/public public/storage" ],( don't forget the comma , if you have any other line after the command above) But you should add the line above in scripts section.

Also You can upload images to public folder instead of storage folder (By this way you will not get problems like above ). for that You need to change config in app/filesystem.php

change

'public' => [
            'driver' => 'local',
            'root' => storage_path('app/public'),
            'url' => env('APP_URL').'/storage',
            'visibility' => 'public',
        ],

to this:

'public' => [
            'driver' => 'local',
            'root' => public_path(),
            'url' => env('APP_URL').'/public',
            'visibility' => 'public',
        ],

and you can store files so:

$pathToFile = Storage::disk('public')->put('uploads/', $file);

now you can insert $pathToFile variable to DB!

Also, you need to run the command:

 php artisan storage:link

Before running this command please check if the storage folder is already there or not inside the public folder if it's there then rename it to storage-bk and run the command. This way it creates new shortcut folder storage (storage/app/public).

This works for me : You can add command line in your procfile. worker: php artisan storage:link

After adding this please push your project to heroku again.

worker: php artisan storage:link

Related