protected function addNestedWhereSlice(QueryBuilder $query, $wheres, $offset, $length = null)
{
$whereSlice = array_slice($wheres, $offset, $length);
$whereBooleans = collect($whereSlice)->pluck('boolean');
// Here we'll check if the given subset of where clauses contains any "or"
// booleans and in this case create a nested where expression. That way
// we don't add any unnecessary nesting thus keeping the query clean.
if ($whereBooleans->contains('or')) {
$query->wheres[] = $this->nestWhereSlice($whereSlice, $whereBooleans->first());
} else {
$query->wheres = array_merge($query->wheres, $whereSlice);
}
}