第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

在laravel中的where子句中使用一個查詢結(jié)果的方式是什么,就像我們在SQL查詢中使用

在laravel中的where子句中使用一個查詢結(jié)果的方式是什么,就像我們在SQL查詢中使用

PHP
明月笑刀無情 2021-05-07 22:35:09
我在Laravel中編寫查詢,但它給了我錯誤提示ErrorException:類stdClass的對象無法轉(zhuǎn)換為字符串$subject_ids = DB::table('question_sets')                   ->select('subject_id')                   ->where('test_section_id','=',$testDetail->test_section_id)                   ->distinct()                   ->get();$topic_ids = DB::table('topics')                 ->select('id')                 ->where('subject_id','=',$subject_ids)                 ->get();
查看完整描述

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();


查看完整回答
反對 回復(fù) 2021-05-21
  • 1 回答
  • 0 關(guān)注
  • 190 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號