Skip to content

Commit

Permalink
Fix:fix bug limit special
Browse files Browse the repository at this point in the history
  • Loading branch information
mehdi-fathi committed Apr 9, 2021
1 parent 6c4ff0c commit 406532c
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
6 changes: 3 additions & 3 deletions src/QueryFilter/Queries/Special.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,17 @@ class Special extends BaseClause
*/
public function apply($query): Builder
{
foreach ($this->values as $key => $param) {
foreach ($this->values as $key => $param_value) {
if (!in_array($key, self::$reserve_param['f_params'])) {
throw new \Exception("$key is not in f_params array.");
}
if (is_array($param)) {
if (is_array($param_value)) {
$this->values['orderBy']['field'] = explode(',', $this->values['orderBy']['field']);
foreach ($this->values['orderBy']['field'] as $order_by) {
$query->orderBy($order_by, $this->values['orderBy']['type']);
}
} else {
$query->limit($this->values);
$query->limit($param_value);
}
}

Expand Down
18 changes: 17 additions & 1 deletion tests/Tests/ModelFilterMockTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,23 @@ public function testFParamOrder()
],
]);

//todo ye default asc vase type order bezar
$users = EloquentBuilderTestModelParentStub::filter($this->request->query());

$this->assertSame($users->toSql(), $builder->toSql());
}

public function testFParamLimit()
{
$builder = new EloquentBuilderTestModelParentStub();

$builder = $builder->newQuery()
->limit(5);

$this->request->shouldReceive('query')->andReturn([
'f_params' => [
'limit' => 5,
],
]);

$users = EloquentBuilderTestModelParentStub::filter($this->request->query());

Expand Down

0 comments on commit 406532c

Please sign in to comment.