我試過各種方法來解決這個問題,但沒有爲我工作。Laravel選擇與多個在聲明
第一方法:
$title = Character::find($selected_char->id)->title()->where('title', '=', 'Castle');
$title = $title->where('title', '=', 'City');
$title = $title->get();
第二方法:
$title = Character::find($selected_char->id)->title()->where('title', '=', 'Castle')->where('title', '=', 'City')->get();
第三方法:
$title = DB::select(DB::raw("select * from titles where titles.char_id = 5 and title = 'Castle' and title = 'City'"));
的Ab的無ove方法工作。如果我只用一個where子句,它就可以完美地工作。例如:
$title = Character::find($selected_char->id)->title()->where('title', '=', 'City')->get();
$title = Character::find($selected_char->id)->title()->where('title', '=', 'Castle')->get();
我甚至試圖採取另一列比標題,但它不適用於第二個函數。我想從title表格中檢索標題爲City和Castle的行,並且在單個select語句中使用了多個where子句,並且它工作正常。不是現在。有什麼建議麼?提前致謝。
$ title = Character :: find($ selected_char-> id) - > title() - > whereIn('title',array('City','Castle')) - > get();爲我工作。謝謝您的回答。我不知道where子句的這種格式。這對未來肯定會有幫助。 –
不客氣,很高興幫助:-) –