@@ -79,6 +79,7 @@ protected function createRequest($method, $needToValidate = true, $parameters =
7979 'servicesNamespace ' => $ this ->generateNamespace ($ this ->paths ['services ' ]),
8080 'entityNamespace ' => $ this ->getModelClass ($ this ->model ),
8181 'needToValidateWith ' => !is_null (Arr::first ($ parameters , fn ($ parameter ) => $ parameter ['name ' ] === 'with.* ' )),
82+ 'availableRelations ' => $ this ->getAvailableRelations (),
8283 ]);
8384
8485 $ this ->saveClass ('requests ' , "{$ method }{$ modelName }Request " ,
@@ -135,15 +136,15 @@ protected function getSearchValidationParameters(): array
135136 'per_page ' ,
136137 ]);
137138
138- $ parameters ['array ' ] = ['with ' ];
139-
140139 $ parameters ['string ' ] = ['order_by ' ];
141140
142141 $ parameters ['string-nullable ' ] = ['query ' ];
143142
143+ $ parameters ['array ' ] = ['with ' ];
144+
144145 $ parameters ['string-required ' ] = ['with.* ' ];
145146
146- return $ this ->getValidationParameters ($ parameters , false );
147+ return $ this ->getValidationParameters ($ parameters , true );
147148 }
148149
149150 public function getValidationParameters ($ parameters , $ requiredAvailable ): array
@@ -187,7 +188,7 @@ protected function getRules($name, $type, $required, $nullable, $present): array
187188 }
188189
189190 if ($ required ) {
190- $ rules[] = 'required ' ;
191+ array_unshift ( $ rules, 'required ' ) ;
191192 }
192193
193194 if ($ nullable ) {
@@ -208,6 +209,22 @@ protected function getRules($name, $type, $required, $nullable, $present): array
208209 ];
209210 }
210211
212+ protected function getAvailableRelations (): array
213+ {
214+ $ availableRelations = [];
215+
216+ $ relations = $ this ->prepareRelations ();
217+
218+ foreach ($ relations as $ type => $ entities ) {
219+ array_push (
220+ $ availableRelations ,
221+ ...Arr::map ($ entities , fn ($ entity ) => $ this ->getRelationName ($ entity , $ type )),
222+ );
223+ }
224+
225+ return $ availableRelations ;
226+ }
227+
211228 private function getEntityName ($ method ): string
212229 {
213230 if ($ method === self ::SEARCH_METHOD ) {
0 commit comments