1 回答

TA貢獻1784條經(jīng)驗 獲得超9個贊
在下面的查詢
$subject_ids = DB::table('question_sets')
->select('subject_id')
->where('test_section_id','=',$testDetail->test_section_id)
->distinct()->get();
您正在獲取一個集合,如果您想要一個特定的值,則可以使用它first() ,然后您可以
$subject_id = DB::table('question_sets')
->select('subject_id')
->where('test_section_id','=',$testDetail->test_section_id)
->distinct()
->pluck('name')
->first();
和
$topic_ids = DB::table('topics')
->select('id')
->where('subject_id','=',$subject_id)
->get();
或者,如果您想與所有$ subject_ids匹配,則應(yīng)使用toArray()和whereIn喜歡
$subject_ids = DB::table('question_sets')
->select('subject_id')
->where('test_section_id','=',$testDetail->test_section_id)
->distinct()
->pluck('subject_id')
->toArray();
和
$topic_ids = DB::table('topics')
->select('id')
->whereIn('subject_id', $subject_ids)
->get();
- 1 回答
- 0 關(guān)注
- 190 瀏覽
添加回答
舉報