[英]Get Values from comma separated ids as foreign key
我有兩張桌子
a> 導師 b> 科目
在導師表中,我在“tutor.tut_subjects_id”字段中的值為 1,2,它們是主題表的主要 id,其中 1 代表兩個不同的科目,即數學和物理。
我正在使用以下代碼顯示每個導師的科目數
在 controller 文件中:
$feat_tuts = DB::table('tutors')
->join('subject', 'tutors.tut_subjects_id', '=', 'subject.id')
->where('tutors.tut_feat', 'yes')
->get();
return view('Frontend/pages/home',compact(['allcategories','feat_courses','feat_tuts']));
在刀片文件中:
@foreach($feat_tuts as $each_feat_tuts)
{{$each_feat_tuts->name}}
@endforeach
但是我從主題表中只得到一個數據,即“數學”。
我需要知道如何顯示主題表中的兩個數據,即數學和物理。
請幫我。
提前致謝。
$feat_tuts = \DB::table('tutors') ->select('tutors.*',\DB::raw("GROUP_CONCAT(subject.name) as subject_name")) ->leftjoin('subject',\ DB::raw("FIND_IN_SET(subject.id,utors.tut_subjects_id)"),">",\DB::raw("'0'")) ->where('tutors.tut_feat', 'yes') ->groupBy('tutors.id') ->get();
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.