【发布时间】:2018-07-13 16:22:01
【问题描述】:
我有这三张桌子:
Table 1. users
'first_name', 'last_name', 'bio', 'image', 'email', 'password', 'user_group','remember_token',
Table 2. professions
'id', 'title',
Table 3 user_profesions
'id','user_id','profession_id'
我将 users 表与 user_professions 表结合起来,如下所示:
public function index(){
$mentors = User::where('user_group', 2)->get();
$all_professions = Profession::get();
foreach($mentors as $mentor) {
$mentor->professions = UserProfession::where('user_id', $mentor->id)->get();
}
dd($mentors);
return view('mentors.list-of-mentors')->with(['mentors'=>$mentors, 'all_professions' => $all_professions]);
}
所以当我死的时候它给了我这个
我也通过了职业表中的所有职业。 鉴于我正在这样做
@foreach($mentors as $mentor)
{{$mentor->first_name}}
@foreach($all_professions as $profession)
{{$profession}}
@endforeach
@endforeach
我被困在这里我不知道如何让特定用户出现的职业..有人可以帮我..吗?
【问题讨论】:
标签: laravel