Tuesday, February 28, 2017

Laravel 5.3 not displaying saved image

I have a function where I import data from an api endpoint. From that endpoint I get an array of json objects where each has a link for an image. I am uploading an image and saving data in my function like so:

 $imageName = uniqid(true) . '-' . $paper['foldername'];
                    $path = public_path('uploads/' . $imageName);
                    Image::make('http://' . $paper['thumb_medium'])->save($path);

                    Issue::create([
                      'magazine_id'   => $paper['magazineId'],
                      'title'         => $paper['title'],
                      'date'          => $paper['date'],
                      'foldername'    => $paper['foldername'],
                      'image'         => $imageName,
                    ]);

I am displaying uploaded images in the frontpage of my app. Most of the images are displayed, but some are not. In the DB, each Issue that was created, has a value in the image field. And on checking the uploads folder, the file with raw image data is created for each Issue. But at the frontpage the image for some issues is still not being displayed, even though I can't see any difference between the ones that are displayed and the ones that are not. I have checked for the ones that I don't get the image being displayed, if I am getting the link for the image and if the image exists on that link, by doing:

dd($paper['thumb_medium']))

And the image does exist on the link I am provided with but the image is not being displayed after uploading it locally. On checking the link locally:

http://ift.tt/2m2FcuB

I get:

NotFoundHttpException in RouteCollection.php line 161:

I am not sure how to fix this?




via Leff

Advertisement