Skip to content

Commit 9a247bc

Browse files
committed
Adding key to match filter.
1 parent e7fdb89 commit 9a247bc

File tree

2 files changed

+41
-1
lines changed

2 files changed

+41
-1
lines changed

src/Filters/Filter.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,7 @@ public function jsonSerialize()
222222
'title' => $this->title(),
223223
'description' => $this->description(),
224224
'column' => $this->column(),
225+
'key' => static::uriKey(),
225226
], function (array $initial) {
226227
return $this->relatedRepositoryKey ? array_merge($initial, [
227228
'repository' => $this->getRelatedRepository(),
@@ -231,7 +232,6 @@ public function jsonSerialize()
231232

232233
if ($this->isAdvanced()) {
233234
$serialized = array_merge($serialized, [
234-
'key' => static::uriKey(),
235235
'rules' => $this->rules(app(Request::class)),
236236
'options' => method_exists($this, 'options')
237237
? collect($this->options(app(Request::class)))->map(function ($key, $value) {

tests/Unit/MatchableFilterTest.php

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<?php
2+
3+
namespace Binaryk\LaravelRestify\Tests\Unit;
4+
5+
use Binaryk\LaravelRestify\Filters\MatchFilter;
6+
use Binaryk\LaravelRestify\Tests\IntegrationTest;
7+
use Illuminate\Testing\Fluent\AssertableJson;
8+
9+
class MatchableFilterTest extends IntegrationTest
10+
{
11+
public function test_matchable_filter_has_key(): void
12+
{
13+
$filter = new class extends MatchFilter {
14+
15+
};
16+
17+
tap(
18+
AssertableJson::fromArray($filter->jsonSerialize()),
19+
function (AssertableJson $json) {
20+
$json
21+
->dd()
22+
->dump()
23+
->where('type', 'multiselect')
24+
->where('advanced', true)
25+
->where('title', 'Status filter')
26+
->where('description', 'Short description')
27+
->where('column', 'status')
28+
->where('key', 'status-filter')
29+
->where('rules', [
30+
'status' => ['required'],
31+
])
32+
->where('options', [[
33+
'label' => 'Draft',
34+
'property' => 'draft',
35+
]])
36+
;
37+
}
38+
);
39+
}
40+
}

0 commit comments

Comments
 (0)