表中有许多匹配的凭据插入到foreach循环中,但是我只从第一个foreach元素获得结果。我怎样才能解决这个问题呢?
foreach($matches as $match)
{
$object = $match->object;
$sales->whereRaw("match (`object`) against (?)", array($object));
if($match->colourBase == '1')
{
$sales->where('colour', '=', 'CC');
$sales->orWhere('colour', '=', 'CC+DD');
if($match->maxPrice)
{
$sales->where('price', '<=', $match->maxPrice);
}
if($match->minPrice)
{
$sales->where('price', '>=', $match->minPrice);
}
}
}
$results = $sales->orderBy('sales.updated_at', 'asc')->get();
@update
这就是我得到$matches 的方式 $matches = Match::where('PeopleID', '=', $id)->get();
如果只需要一条记录使用first()
函数。不需要使用foreach。:)
$matches = Match::where('PeopleID', '=', $id)->first();