2016-05-01 60 views
0

我嘗試返回我的搜索結果放入數組中的刀片顯示,但得到的錯誤:在0bfe77047992e2dce86ae561e266494c線37如何追加到導致Laravel 5.1

$persons = persons::where('name','like',"%$search_term%")->lists('id'); 

foreach($persons as $person) 
{ 
     $trials = trial::with('samples')->with('persons')->where('persons_id', '=', $person)->get(); 
} 

FatalErrorException:呼叫 未定義的方法照亮\數據庫\雄辯\收藏::追加()

我嘗試這與+陣列,但得到的錯誤

+0

請爲您的問題添加更多上下文。人和試用和樣本都是雄辯的模型,對吧?你究竟想要完成什麼? – PawelMysior

+0

我需要獲得person_id列表中的人名列表 –

+0

請參閱我的回答。我還建議您以單數和駝峯形式命名模型。這種方式更具可讀性。 – PawelMysior

回答

2

可以使用whereIn()查詢生成器的方法。請參閱docs

$persons = Person::where('name', 'like', '%$search_term%')->lists('id'); 

$trials = Trial::with('samples')->with('persons')->whereIn('person_id', $persons)->get();