0

I am using Laravel 5.4 when I get the image using id with map function and return the image directory I got this error

This is function inside controller

 $shipping = DB::table('shipping')
            ->select('shipping.id','products.name','shipping.is_return','shipping.pro_id as pid','shipping.tracking_url')
            ->join('products','shipping.pro_id','=','products.id')
            ->orderBy('shipping.id', 'desc')
            ->limit('5')->get();

        $shipping->map(function ($ship) {
           $directory = 'uploads/products/images/'.$ship->pid;
           if (is_dir($directory)) {
            $files = scandir ($directory);
            $img_file = $directory.'/'.$files[2];
            $ship->front_img = $img_file;
            print_r($ship['front_img']);exit;
           }           
         });

When I try to print the output it shows the error.

2
  • 2
    Do $ship->front_img instead Commented Jul 8, 2017 at 11:55
  • tried that also...the same error occurs Commented Jul 8, 2017 at 11:57

1 Answer 1

1

You are trying to get value using array but $ship is object

$shipping = DB::table('shipping')->select('shipping.id','products.name','shipping.is_return','shipping.pro_id as pid','shipping.tracking_url')
            ->join('products','shipping.pro_id','=','products.id')
            ->orderBy('shipping.id', 'desc')
            ->limit('5')->get();

        $shipping->map(function ($ship) {
           $directory = 'uploads/products/images/'.$ship->pid;
           if (is_dir($directory)) {
            $files = scandir ($directory);
            $img_file = $directory.'/'.$files[2];
            $ship->front_img = $img_file;
            print_r($ship->front_img);exit; //change here
           }           
         });
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.