如何使用刀片中的外键访问表列中的内容到目前为止,我拥有此功能,但无法使用。Laravel访问刀片中的外键表列
询价型号/关系
public function client()
{
return $this->belongsTo(Client::class);
}
public function device()
{
return $this->belongsTo(Device::class);
}
客户端模型
public function inquiry()
{
return $this->hasMany(Inquiry::class);
}
public function devices()
{
return $this->hasMany(Device::class);
}
设备型号
public function inquiry()
{
return $this->hasMany(Inquiry::class);
}
控制器
public function index()
{
$inquiries = Inquiry::all();
return view('stream.index', compact('inquiries'));
}
查看
@foreach($inquiries as $inquiryKey => $inquiryValue)
<tr>
// stream id is the foreign that table has a column with names ...
<th scope="row">{{ $inquiryValue->stream_id }}</th> // works
<th scope="row">{{ $inquiryValue->stream_id->name }}</th> // does not work -> trying to get property of none object
的stream_id是表中的字段? –
你只是通过foreach像$查询 - >客户端然后你可以使用客户端表数据 –
@AddWebSolutionPvtLtd你能给我一个示例代码请 – junikear