我想获取每个学生拥有的兄弟姐妹列表
控制器:
public function show($id)
{
$finddata = Student::orderBy('id', 'asc')->get();
$BS = Student::with('Family')->get();
return View('students.list' ,compact('finddata','BS'));
}
学生模型:外键:family_id
public function family()
{
return $this->belongsTo(family::class, 'family_id');
}
public function siblings()
{
return $this->belongsTo("Family", "family_id");
}
家庭模式:
public function siblings()
{
return $this->hasMany("Student");
}
查看:
@foreach($finddata as $record)
{{$finddata->studentname}}
@endforeach
@foreach($BS->siblings as sibling)
{{sibling->name}}
@endforeach
错误:“此集合实例上不存在[兄弟姐妹]属性。(视图:\ views \ students \ list.blade.php)”