Skip to content

Commit 6a2daee

Browse files
authored
Merge pull request #5651 from Laravel-Backpack/add-setQuery()-method
Add set query() method
2 parents 23a0630 + c0cb857 commit 6a2daee

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

src/app/Library/CrudPanel/Traits/Query.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace Backpack\CRUD\app\Library\CrudPanel\Traits;
44

5+
use Illuminate\Contracts\Database\Query\Builder as QueryBuilder;
56
use Illuminate\Database\Eloquent\Builder;
67

78
trait Query
@@ -63,6 +64,13 @@ public function addBaseClause($function)
6364
return $this;
6465
}
6566

67+
public function setQuery(QueryBuilder $query)
68+
{
69+
$this->query = $query;
70+
71+
return $this;
72+
}
73+
6674
/**
6775
* Use eager loading to reduce the number of queries on the table view.
6876
*

tests/Unit/CrudPanel/CrudPanelQueryTest.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,4 +180,13 @@ public function testItGetTheQueryCountFromAPreviousCount()
180180

181181
$this->assertEquals(5, $this->crudPanel->getTotalQueryCount());
182182
}
183+
184+
public function testItCanSetTheQueryOnTheCrudPanel()
185+
{
186+
$this->assertEquals(User::query()->toSql(), $this->crudPanel->query->toSql());
187+
188+
$this->crudPanel->setQuery(User::query()->where('id', 1));
189+
190+
$this->assertEquals(User::query()->where('id', 1)->toSql(), $this->crudPanel->query->toSql());
191+
}
183192
}

0 commit comments

Comments
 (0)