我有 3 個表“用戶”、“學生”和“注冊”。每個表都與 hasOne 關系鏈接。我想從班級表中獲取student_id的值。是否可以找到?其實我是新人,我不明白//代碼 <a href="{{route('gallary.view',['stud_id' =>auth()->user()->student()->registration->student_id])}}">//錯誤 Undefined property: Illuminate\Database\Eloquent\Relations\HasOne::$registration
3 回答

慕森王
TA貢獻1777條經驗 獲得超3個贊
如果學生有過一種關系而不是使用
{{route('gallary.view',['stud_id' =>auth()->user()->student->registration->student_id])}}
只需在學生之后刪除圓括號即可。

偶然的你
TA貢獻1841條經驗 獲得超3個贊
如果你已經正確定義了你的關系,你可以做這樣的事情。
@php
$user_details = User::('student.registration')->where('id',auth()->user()->id)->first();
$student_id = $user_details->student->registration->student_id;
@endphp
{{route('gallary.view',['stud_id' =>$student_id])}}

慕神8447489
TA貢獻1780條經驗 獲得超1個贊
您應該()
從學生關系中刪除
正確的代碼是
<a href="{{route('gallary.view',['stud_id' =>auth()->user()->student->registration->student_id])}}"
- 3 回答
- 0 關注
- 122 瀏覽
添加回答
舉報
0/150
提交
取消