0
我有一个具有许多预约模型的客户端模型。约会属于客户。我试图返回显示客户姓名的结果以及索引刀片上的约会列表。这是我到目前为止的代码:此收藏实例上不存在此属性
客户端模型
public function appointment()
{
return $this->hasMany(Appointment::class);
}
约会型号
public function client()
{
return $this->belongsTo(Client::class);
}
Controlller
$clients = Client::with('appointment')->get();
//dd($clients);
return view('scheduler')->withclients($clients);
刀片
@foreach($clients as $client
{{ $client->name }}
{{ $client->appointment->id }}
@endforeach
如何打印$客户名称及其约会列表?我已经尝试过有关这个问题的其他帮助,但我不清楚我的错在哪里。
你错过了'@ foreach'行的paranthese。此外,你是怎么想出'withclients()'函数的。它看起来怎样?您可以通过'return view('..') - > with(compact(“clients”));将值传递给视图 – manniL