Home > Mobile >  how to use database saved links of image to get images from laravel folder
how to use database saved links of image to get images from laravel folder

Time:01-20

i have saved images in 'public/images' folder in Laravel and the link/name is saved in mysql database. all i want to get all images via api call. the problem is i can get a single image easily but couldnt get all the images.[[[enter image description here](https://i.stack.imgur.com/9gerk.jpg)](https://i.stack.imgur.com/MIBIk.jpg)](https://i.stack.imgur.com/QcPQm.jpg)

i have no issue with single image however unable to get all at once. thanks

CodePudding user response:

Try this instead Store the only image name and extension into database and then retrieve it by using DB and use asset to get image, refer the following code as practice.

$custom_data = array();
                        for ($i = 0; i <= $total_images; $i  ) {
                            $image_name = $data[$i]->image;
                            if ($image_name != "") {
                                $image_with_path = asset('public/products/') . '/' . $image_name;
                            } else {
                                $image_with_path = "";
                            }
                            $custom_data['image'] = $image_with_path;
                        }
  • Related