|
|
@@ -188,11 +188,36 @@ class EloquentRepository extends Repository implements TreeRepository
|
|
|
[$column, $type, $cast] = $model->getSort();
|
|
|
|
|
|
if (empty($column) || empty($type)) {
|
|
|
+ $orders = $model->findQueryByMethod('orderBy')->merge($model->findQueryByMethod('orderByDesc'));
|
|
|
+
|
|
|
+ $model->resetOrderBy();
|
|
|
+
|
|
|
+ $orders->each(function ($orderBy) use ($model) {
|
|
|
+ $column = $orderBy['arguments'][0];
|
|
|
+ $type = $orderBy['method'] === 'orderByDesc' ? 'desc' : ($orderBy['arguments'][1] ?? 'asc');
|
|
|
+ $cast = null;
|
|
|
+
|
|
|
+ $this->addOrderBy($model, $column, $type, $cast);
|
|
|
+ });
|
|
|
+
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
$model->resetOrderBy();
|
|
|
|
|
|
+ $this->addOrderBy($model, $column, $type, $cast);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @param Grid\Model $model
|
|
|
+ * @param string $column
|
|
|
+ * @param string $type
|
|
|
+ * @param string $cast
|
|
|
+ *
|
|
|
+ * @throws \Exception
|
|
|
+ */
|
|
|
+ protected function addOrderBy(Grid\Model $model, $column, $type, $cast)
|
|
|
+ {
|
|
|
$explodedCols = explode('.', $column);
|
|
|
$isRelation = empty($explodedCols[1]) ? false : method_exists($this->model(), $explodedCols[0]);
|
|
|
|
|
|
@@ -345,7 +370,7 @@ class EloquentRepository extends Repository implements TreeRepository
|
|
|
*/
|
|
|
protected function setPaginate(Grid\Model $model)
|
|
|
{
|
|
|
- $paginate = $model->findQueryByMethod('paginate');
|
|
|
+ $paginate = $model->findQueryByMethod('paginate')->first();
|
|
|
|
|
|
$model->rejectQuery(['paginate']);
|
|
|
|