skip to Main Content

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

Answers


  1. Chosen as BEST ANSWER

    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


  2. 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');
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search