add whereNotInOrder() to repository
This commit is contained in:
@@ -190,9 +190,7 @@ class PirepController extends Controller
|
|||||||
$this->pirepRepo->pushCriteria($criterea);
|
$this->pirepRepo->pushCriteria($criterea);
|
||||||
|
|
||||||
$pireps = $this->pirepRepo
|
$pireps = $this->pirepRepo
|
||||||
->findWhere(['status', '!=', PirepState::CANCELLED])
|
->whereNotInOrder('status', [PirepState::CANCELLED, PirepState::DRAFT], 'created_at', 'desc')
|
||||||
->findWhere(['status', '!=', PirepState::DRAFT])
|
|
||||||
->orderBy('created_at', 'desc')
|
|
||||||
->paginate();
|
->paginate();
|
||||||
|
|
||||||
return view('admin.pireps.index', [
|
return view('admin.pireps.index', [
|
||||||
|
|||||||
@@ -76,4 +76,29 @@ abstract class Repository extends \Prettus\Repository\Eloquent\BaseRepository
|
|||||||
return $q;
|
return $q;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Find records with a WHERE clause but also sort them
|
||||||
|
* @param string $col
|
||||||
|
* @param array $values
|
||||||
|
* @param string $sort_by
|
||||||
|
* @param string $order_by
|
||||||
|
* @return $this
|
||||||
|
*/
|
||||||
|
public function whereNotInOrder($col, $values, $sort_by, $order_by = 'asc')
|
||||||
|
{
|
||||||
|
return $this->scopeQuery(function ($query) use ($col, $values, $sort_by, $order_by) {
|
||||||
|
$q = $query->whereNotIn($col, $values);
|
||||||
|
# See if there are multi-column sorts
|
||||||
|
if (\is_array($sort_by)) {
|
||||||
|
foreach ($sort_by as $key => $sort) {
|
||||||
|
$q = $q->orderBy($key, $sort);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$q = $q->orderBy($sort_by, $order_by);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $q;
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user