【发布时间】:2017-01-16 23:16:15
【问题描述】:
我有以下错误。客户模型与约会模型有关系。当我用他们的 id (1) 替换变量 $client 时,它成功地返回了一个约会集合。但是使用变量它返回NULL。我正在尝试遍历每个客户的约会以计算出总持续时间。我的错误是,在每次循环使用之前的 $client 变量时,我无法检索约会。
仅供参考,foreach $clients as $client 循环返回所有客户端的集合。
在 null 上调用成员函数约会()
公共函数自动生成(请求 $request){
$date1 = $request->input('date_from');
$date2 = $request->input('date_to');
$customer = $request->input('customer_account');
if(count($customer) > 0)
{
$clients = Customer::find($customer)->client()->get();
foreach($clients as $client)
{
$appointments = Client::find($clients)->appointments()->get();
foreach($appointments as $appointment)
{
//other code
}
}
//other code
}
$invoices = Invoice::all();
return redirect('invoice');
}
【问题讨论】:
标签: php laravel-5.3