如何使用 auth()->user()->student()->registration

我有 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


潇湘沐
浏览 103回答 3
3回答

慕森王

如果学生有过一种关系而不是使用{{route('gallary.view',['stud_id'&nbsp;=>auth()->user()->student->registration->student_id])}}只需在学生之后删除圆括号即可。

偶然的你

如果你已经正确定义了你的关系,你可以做这样的事情。@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

您应该()从学生关系中删除正确的代码是<a&nbsp;href="{{route('gallary.view',['stud_id'&nbsp;=>auth()->user()->student->registration->student_id])}}"
打开App,查看更多内容
随时随地看视频慕课网APP