public function enroll()
{
return $this->hasMany(Enrolls::class,'cid');
}
public function classes()
{
return $this->belongsTo(Classes::class);
}
public function index()
{
$enrolls = Enrolls::all();
return view('home')->with('enrolls', $enrolls);
}
{{$enroll->classes->title}}
我试图从登记表中获取数据。其中包含两个外键。
SCREENSHOT
答案 0 :(得分:-1)
您应该尝试以下操作:
public function index()
{
$enrolls = Enrolls::with('classes')->get();
return view('home',compact('enrolls'));
}