Reputation: 897
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.
Upvotes: 0
Views: 434
Reputation: 16436
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
}
});
Upvotes: 1