1
votes

I have a problem with displaying pictures in View for my project in Laravel..destination path in my application where the photos were saved is: public_path (/ images) but recently I put the project on the server in cpanel, and to get rid of / public from the url, I used a google article, and I made a folder called laravel outside the public_html folder, in which I keep the application files and in public_html I keep only the files that were in the public folder of the application. In View I display the pictures as follows: "{{asset ('images /'. $ Img-> file_name)}}" .. Only it is no longer displayed. Pictures are saved but no longer displayed. I mention that it is saved in the Laravel folder which is outside the public_html folder..and I think that public / images was created automatically there..I would like to know if anyone has faced such a thing and what is the solution. thank you

2
You need to make a sym link with your root/public_html/public path to root/laravel/publicsta
@sta i guess you can do that but that sounds vague. OP should probably just read public_html as public instead. Theyre 2 different names for the same thing, depending on how you have apache configured.Flame
Have a look at stackoverflow.com/questions/35461322/… written in 2016.Donkarnash
@Donkarnash it's not enough. ..is created: public / images in laravel_project folder and saved there..instead of public_html / public / imagesEugen Gîrlescu
I guess the images folder should be within public_html : public_html/images and once require_once __DIR__.'/public/index.php'; is changed to require_once __DIR__.'../public_html/index.php'; it worksDonkarnash

2 Answers

1
votes

I solved the problem like this: In AppServiceProvider in register() I put this code:

$this->app->bind('path.public', function () {
        return base_path('../public_html');
    });

and now I have public_html/images and there my images are saved..and the rest of myy app, outside public_html folder in a different folder named laravel_project

0
votes

In Laravel 8, I solved it adding this to the /app/Providers/AppServiceProvider.php in register method:

public function register()
{
    $this->app->bind('path.public', function () {
        return base_path('../public_html');
    });
}

But in order to create the symlink from the "php artisan storage:link" command, I also had to add this code to /bootstrap/app.php, just after the last singleton:

$app->bind('path.public', function () {
    return base_path("../public_html");
});

Finally I used this code to get the image that will be sent to my blade template:

$image=Storage::disk('public')->url('path_to_image');