@@ -176,9 +176,11 @@ abstract class AbstractValidators implements ValidatorFactoryInterface
176176 *
177177 * @param mixed|null $record
178178 * the record being updated, or null if creating a resource.
179+ * @param array $data
180+ * the data that is being validated.
179181 * @return mixed
180182 */
181- abstract protected function rules ($ record = null ): array ;
183+ abstract protected function rules ($ record, array $ data ): array ;
182184
183185 /**
184186 * Get query parameter validation rules.
@@ -208,7 +210,8 @@ public function supportsClientIds(): bool
208210 return $ this ->clientIds ;
209211 }
210212
211- return $ this ->clientIds = collect ($ this ->rules ())->has ('id ' );
213+ return $ this ->clientIds = collect ($ this ->rules (null , []))
214+ ->has ('id ' );
212215 }
213216
214217 /**
@@ -217,8 +220,8 @@ public function supportsClientIds(): bool
217220 public function create (array $ document ): ValidatorInterface
218221 {
219222 return $ this ->validatorForResource (
220- $ this ->dataForCreate ($ document ),
221- $ this ->rules (),
223+ $ data = $ this ->dataForCreate ($ document ),
224+ $ this ->rules (null , $ data ),
222225 $ this ->messages (),
223226 $ this ->attributes ()
224227 );
@@ -230,8 +233,8 @@ public function create(array $document): ValidatorInterface
230233 public function update ($ record , array $ document ): ValidatorInterface
231234 {
232235 return $ this ->validatorForResource (
233- $ this ->dataForUpdate ($ record , $ document ),
234- $ this ->rules ($ record ),
236+ $ data = $ this ->dataForUpdate ($ record , $ document ),
237+ $ this ->rules ($ record, $ data ),
235238 $ this ->messages ($ record ),
236239 $ this ->attributes ($ record )
237240 );
@@ -259,11 +262,11 @@ public function delete($record): ?ValidatorInterface
259262 */
260263 public function modifyRelationship ($ record , string $ field , array $ document ): ValidatorInterface
261264 {
262- $ data = $ this ->dataForRelationship ($ record , $ field , $ document );
265+ $ resource = ResourceObject:: create ( $ this ->dataForRelationship ($ record , $ field , $ document) );
263266
264267 return $ this ->factory ->createRelationshipValidator (
265- ResourceObject:: create ( $ data ) ,
266- $ this ->relationshipRules ($ record , $ field ),
268+ $ resource ,
269+ $ this ->relationshipRules ($ record , $ field, $ resource -> all () ),
267270 $ this ->messages (),
268271 $ this ->attributes ()
269272 );
@@ -552,11 +555,12 @@ protected function dataForRelationship($record, string $field, array $document):
552555 *
553556 * @param mixed $record
554557 * @param string $field
558+ * @param array $data
555559 * @return array
556560 */
557- protected function relationshipRules ($ record , string $ field ): array
561+ protected function relationshipRules ($ record , string $ field, array $ data ): array
558562 {
559- return collect ($ this ->rules ($ record ))->filter (function ($ v , $ key ) use ($ field ) {
563+ return collect ($ this ->rules ($ record, $ data ))->filter (function ($ v , $ key ) use ($ field ) {
560564 return Str::startsWith ($ key , $ field );
561565 })->all ();
562566 }
0 commit comments