【发布时间】:2021-04-03 01:10:46
【问题描述】:
我在项目中还有一个这样的关系,它可以工作,但这不起作用。我在屏幕上看不到任何价值。它返回空值。我不擅长 Laravel 和数据库中的关系。我认为我的控制器和路由是正确的,但我的关系不正确。
My User 模型包含以下关系:
public function follows(){
return $this->hasMany('App\Models\Follow');
}
My Follow 模型包含以下关系:
public function user(){
return $this->belongsTo('App\Models\User');
}
我的刀片是:
@foreach ($user->follows as $followr)
<h6><strong>{{$followr}}</strong></h6>
@endforeach
【问题讨论】:
-
请提供您的表结构,这通常是因为您没有像 Laravel 预期的那样定义主键或外键