2017-07-08 4 views
0

laravelに配列誤差としてのタイプはstdClassのオブジェクトを使用し、これは、コントローラは、私は、マップ機能でIDを使用して画像を得るとき、私はLaravel 5.4を使用しています5.4

内部関数である私は、このエラー

を得た画像のディレクトリを返すことができません。

$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; 
      }   
     }); 

出力を印刷しようとすると、エラーが表示されます。

+2

います '$ ship-> front_img'である代わりに – colburton

+0

も...同じエラーが発生することを試みました – Karthiga

答えて

1

あなたは、配列を使用して値を取得しようとしているが、$shipがオブジェクト

$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 
      }   
     }); 
関連する問題