为什么我不能用餐桌上的食物叫名字?

时间:2018-12-07 14:55:14

标签: laravel-5

公共功能订单清单(请求$ request){         $ id = $ request-> id;

    $data['order'] = Order::where('shop_id',$id)->orderBy('id')->get();
            foreach($data['order'] as $orders){
                $orders->shop = Shop::where('id',$orders->shop_id)->first();
                $orders->food = Food::where('id',$orders->food_id)->get();
            }   
            return $orders->food->name;
    return view ('administrator.users.list_order.index',$data);
}

1 个答案:

答案 0 :(得分:0)

如果您建立了适当的口才关系,则可以这样重写此代码:

A

在此处签出文档:https://laravel.com/docs/5.7/eloquent-relationships