如何使用刀片中的外鍵訪問表列中的內容到目前爲止,我擁有此功能,但無法使用。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