Skip to content

Commit 65c8e4b

Browse files
committed
修复 当Grid无数据时使用了hidePage()页面报错 #53
1 parent 2d93e85 commit 65c8e4b

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

src/Grid/Model.php

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ protected function setPaginate()
177177
return $query['method'] == 'paginate';
178178
});
179179

180-
if (!$this->usePaginate) {
180+
if ($this->grid->isHidePage()) {
181181
$query = [
182182
'method' => 'get',
183183
'arguments' => [],
@@ -400,10 +400,8 @@ public function displayData($data)
400400
$columns = $this->grid->getColumns();
401401
$items = collect();
402402

403-
404403
foreach ($data as $key => $row) {
405404
$item = [];
406-
407405
foreach ($this->grid->getAppendFields() as $field) {
408406
data_set($item, $field, data_get($row, $field));
409407
}
@@ -476,19 +474,25 @@ public function get()
476474
$this->model = $this->relation->getQuery();
477475
}
478476

477+
479478
$this->setSort();
479+
480+
480481
$this->setPaginate();
481482

482483

483484
$this->queries->unique()->each(function ($query) {
484485
$this->model = call_user_func_array([$this->model, $query['method']], $query['arguments']);
485486
});
486487

487-
488488
$data = $this->model;
489489

490490
if ($this->model instanceof Collection) {
491-
return $this->displayData($data);
491+
if ($data->count() > 0) {
492+
return $this->displayData($data);
493+
} else {
494+
return $data;
495+
}
492496
}
493497

494498
if ($this->model instanceof LengthAwarePaginator) {

0 commit comments

Comments
 (0)