我试过各种方法来解决这个问题,但没有为我工作。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子句的这种格式。这对未来肯定会有帮助。 –
不客气,很高兴帮助:-) –