public function action_detail($orderId)
{
$customerWithOrderDetails = Customer::with(array('order' => function($query)
{ global $orderId;
$query->where('id', '=', $orderId);
}, 'order.orderdetail', 'order.attachment'))->find(Auth::user()->id);
return var_dump($customerWithOrderDetails);
}
I am getting "variable undefined" error. Why?
$orderId is not a global variable, but a variable of a parent function. Try this:
function($query) use ($orderId)
{
$query->where('id', '=', $orderId);
}
instead of:
function($query)
{ global $orderId;
$query->where('id', '=', $orderId);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With