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 1919
2020namespace LaravelJsonApi \Laravel \Console ;
2121
22+ use Illuminate \Support \Str ;
23+ use LaravelJsonApi \Core \Query \Custom \ExtendedQueryParameters ;
2224use Symfony \Component \Console \Input \InputOption ;
2325
2426class MakeQuery extends GeneratorCommand
@@ -82,6 +84,36 @@ protected function getClassType(): string
8284 return 'Query ' ;
8385 }
8486
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+
85117 /**
86118 * @inheritDoc
87119 */
Original file line number Diff line number Diff line change @@ -41,6 +41,11 @@ class {{ class }} extends ResourceQuery
4141 'string',
4242 JsonApiRule::sort(),
4343 ],
44+ '{{ withCount }}' => [
45+ 'nullable',
46+ 'string',
47+ JsonApiRule::countable(),
48+ ],
4449 ];
4550 }
4651}
Original file line number Diff line number Diff line change @@ -33,6 +33,11 @@ class {{ class }} extends ResourceQuery
3333 ],
3434 'page' => JsonApiRule::notSupported(),
3535 'sort' => JsonApiRule::notSupported(),
36+ '{{ withCount }}' => [
37+ 'nullable',
38+ 'string',
39+ JsonApiRule::countable(),
40+ ],
3641 ];
3742 }
3843}
Original file line number Diff line number Diff line change @@ -158,6 +158,7 @@ private function assertQueryCreated(): void
158158 'class PostQuery extends ResourceQuery ' ,
159159 "'page' => JsonApiRule::notSupported(), " ,
160160 "'sort' => JsonApiRule::notSupported(), " ,
161+ "'withCount' => " ,
161162 ];
162163
163164 foreach ($ tests as $ expected ) {
@@ -180,6 +181,7 @@ private function assertQueryCollectionCreated(): void
180181 'class PostCollectionQuery extends ResourceQuery ' ,
181182 'JsonApiRule::page(), ' ,
182183 'JsonApiRule::sort(), ' ,
184+ "'withCount' => " ,
183185 ];
184186
185187 foreach ($ tests as $ expected ) {
You can’t perform that action at this time.
0 commit comments