File tree Expand file tree Collapse file tree 4 files changed +44
-0
lines changed
tests/lib/Integration/Console Expand file tree Collapse file tree 4 files changed +44
-0
lines changed Original file line number Diff line number Diff line change 19
19
20
20
namespace LaravelJsonApi \Laravel \Console ;
21
21
22
+ use Illuminate \Support \Str ;
23
+ use LaravelJsonApi \Core \Query \Custom \ExtendedQueryParameters ;
22
24
use Symfony \Component \Console \Input \InputOption ;
23
25
24
26
class MakeQuery extends GeneratorCommand
@@ -82,6 +84,36 @@ protected function getClassType(): string
82
84
return 'Query ' ;
83
85
}
84
86
87
+ /**
88
+ * @inheritDoc
89
+ */
90
+ protected function buildClass ($ name )
91
+ {
92
+ $ stub = parent ::buildClass ($ name );
93
+
94
+ return $ this ->replaceAdditional ($ stub );
95
+ }
96
+
97
+ /**
98
+ * Replace additional placeholders.
99
+ *
100
+ * @param string $stub
101
+ * @return string
102
+ */
103
+ protected function replaceAdditional (string $ stub ): string
104
+ {
105
+ $ withCount = ExtendedQueryParameters::withCount ();
106
+
107
+ $ replace = [
108
+ '{{ withCount }} ' => $ withCount ,
109
+ '{{withCount}} ' => $ withCount ,
110
+ ];
111
+
112
+ return str_replace (
113
+ array_keys ($ replace ), array_values ($ replace ), $ stub
114
+ );
115
+ }
116
+
85
117
/**
86
118
* @inheritDoc
87
119
*/
Original file line number Diff line number Diff line change @@ -41,6 +41,11 @@ class {{ class }} extends ResourceQuery
41
41
'string',
42
42
JsonApiRule::sort(),
43
43
],
44
+ '{{ withCount }}' => [
45
+ 'nullable',
46
+ 'string',
47
+ JsonApiRule::countable(),
48
+ ],
44
49
];
45
50
}
46
51
}
Original file line number Diff line number Diff line change @@ -33,6 +33,11 @@ class {{ class }} extends ResourceQuery
33
33
],
34
34
'page' => JsonApiRule::notSupported(),
35
35
'sort' => JsonApiRule::notSupported(),
36
+ '{{ withCount }}' => [
37
+ 'nullable',
38
+ 'string',
39
+ JsonApiRule::countable(),
40
+ ],
36
41
];
37
42
}
38
43
}
Original file line number Diff line number Diff line change @@ -158,6 +158,7 @@ private function assertQueryCreated(): void
158
158
'class PostQuery extends ResourceQuery ' ,
159
159
"'page' => JsonApiRule::notSupported(), " ,
160
160
"'sort' => JsonApiRule::notSupported(), " ,
161
+ "'withCount' => " ,
161
162
];
162
163
163
164
foreach ($ tests as $ expected ) {
@@ -180,6 +181,7 @@ private function assertQueryCollectionCreated(): void
180
181
'class PostCollectionQuery extends ResourceQuery ' ,
181
182
'JsonApiRule::page(), ' ,
182
183
'JsonApiRule::sort(), ' ,
184
+ "'withCount' => " ,
183
185
];
184
186
185
187
foreach ($ tests as $ expected ) {
You can’t perform that action at this time.
0 commit comments