我如何从json中的另一个CRUD获取价值

时间:2019-07-29 18:23:51

标签: json laravel api laravel-5.8

我从order crud获得了json返回值,如何使其也通过用户ID从User Crud返回了值

这是我的代码

public function vendorindex(Request $request)
    {
        $user = Auth::user();
        if(isset($user->id)){
            $order = Order::where('vendor_id', $user->id)->get();
        }else{
            $order = null;
        }
        return response()->json($order);

    }

我尝试执行此操作,但无法与我一起用我想要的值替换另一个值

 public function vendorindex(Request $request)
    {
        $user = Auth::user();
        if(isset($user->id)){
            $order = Order::where('vendor_id', $user->id)->get();

            foreach($order as $orders){
                $mobile  = User::where($user->mobile);
                $created_at = Order::where($orders->created_at);
                $phonenumber = array(
                    'mobile'  => $mobile, 
                    'created_at' => $created_at
                );

                $orders->created_at = $phonenumber;
            }
        }else{
            $order = null;
        }
        return response()->json($order);

    }

0 个答案:

没有答案