How to append to result in Laravel 5.1


How to append to result in 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();
}

0bfe77047992e2dce86ae561e266494c线路37中的致命错误异常:呼叫到未定义的方法Illuminate''Database''Eloquent''Collection::appends()

我尝试使用+数组,但出现错误

您可以使用查询生成器的whereIn()方法。请参阅文档。

$persons = Person::where('name', 'like', '%$search_term%')->lists('id');
$trials = Trial::with('samples')->with('persons')->whereIn('person_id', $persons)->get();