diff --git a/config/orion.php b/config/orion.php index 5b696766..fe7e6cb0 100644 --- a/config/orion.php +++ b/config/orion.php @@ -49,4 +49,6 @@ */ 'max_nested_depth' => 1, ], + + 'use_validated' => false, ]; diff --git a/src/Concerns/HandlesRelationManyToManyOperations.php b/src/Concerns/HandlesRelationManyToManyOperations.php index 59e2a7cf..0d728ae4 100644 --- a/src/Concerns/HandlesRelationManyToManyOperations.php +++ b/src/Concerns/HandlesRelationManyToManyOperations.php @@ -54,7 +54,9 @@ protected function attachWithTransaction(Request $request, $parentKey) $attachResult = $this->performAttach( $request, $parentEntity, - $request->get('resources'), + config('orion.use_validated') + ? $request->validated('resources') + : $request->get('resources'), $request->get('duplicates', false) ); @@ -271,7 +273,13 @@ protected function detachWithTransaction(Request $request, $parentKey) $this->authorize('update', $parentEntity); - $detachResult = $this->performDetach($request, $parentEntity, $request->get('resources')); + $detachResult = $this->performDetach( + $request, + $parentEntity, + config('orion.use_validated') + ? $request->validated('resources') + : $request->get('resources') + ); $afterHookResult = $this->afterDetach($request, $parentEntity, $detachResult); if ($this->hookResponds($afterHookResult)) { @@ -393,7 +401,9 @@ protected function syncWithTransaction(Request $request, $parentKey) $syncResult = $this->performSync( $request, $parentEntity, - $request->get('resources'), + config('orion.use_validated') + ? $request->validated('resources') + : $request->get('resources'), $request->get('detaching', true) ); @@ -516,7 +526,13 @@ protected function toggleWithTransaction(Request $request, $parentKey) $this->authorize('update', $parentEntity); - $toggleResult = $this->performToggle($request, $parentEntity, $request->get('resources')); + $toggleResult = $this->performToggle( + $request, + $parentEntity, + config('orion.use_validated') + ? $request->validated('resources') + : $request->get('resources') + ); $afterHookResult = $this->afterToggle($request, $parentEntity, $toggleResult); if ($this->hookResponds($afterHookResult)) { diff --git a/src/Concerns/HandlesRelationStandardBatchOperations.php b/src/Concerns/HandlesRelationStandardBatchOperations.php index 4f432457..f511ff3a 100644 --- a/src/Concerns/HandlesRelationStandardBatchOperations.php +++ b/src/Concerns/HandlesRelationStandardBatchOperations.php @@ -53,7 +53,9 @@ protected function batchStoreWithTransaction(Request $request, $parentKey) return $beforeHookResult; } - $resources = $request->get('resources', []); + $resources = config('orion.use_validated') + ? $request->validated('resources', []) + : $request->get('resources', []); $entities = collect([]); $requestedRelations = $this->relationsResolver->requestedRelations($request); @@ -196,7 +198,9 @@ protected function batchUpdateWithTransaction(Request $request, $parentKey) /** @var Model $entity */ $this->authorize('update', [$entity, $parentEntity]); - $resource = $request->input("resources.{$entity->{$this->keyName()}}"); + $resource = config('orion.use_validated') + ? $request->validated("resources.{$entity->{$this->keyName()}}") + : $request->input("resources.{$entity->{$this->keyName()}}"); $this->beforeUpdate($request, $parentEntity, $entity); $this->beforeSave($request, $parentEntity, $entity); diff --git a/src/Concerns/HandlesRelationStandardOperations.php b/src/Concerns/HandlesRelationStandardOperations.php index 66892eb7..06ee3e8f 100644 --- a/src/Concerns/HandlesRelationStandardOperations.php +++ b/src/Concerns/HandlesRelationStandardOperations.php @@ -284,7 +284,9 @@ protected function storeWithTransaction(Request $request, $parentKey) $request, $parentEntity, $entity, - $request->all(), + config('orion.use_validated') + ? $request->validated() + : $request->all(), $request->get('pivot', []) ); @@ -636,7 +638,9 @@ protected function updateWithTransaction(Request $request, $parentKey, $relatedK $request, $parentEntity, $entity, - $request->all(), + config('orion.use_validated') + ? $request->validated() + : $request->all(), $request->get('pivot', []) ); diff --git a/src/Concerns/HandlesStandardBatchOperations.php b/src/Concerns/HandlesStandardBatchOperations.php index 456782c1..8a76f4a2 100644 --- a/src/Concerns/HandlesStandardBatchOperations.php +++ b/src/Concerns/HandlesStandardBatchOperations.php @@ -46,7 +46,9 @@ protected function batchStoreWithTransaction(Request $request) $this->authorize('create', $resourceModelClass); - $resources = $request->get('resources', []); + $resources = config('orion.use_validated') + ? $request->validated('resources', []) + : $request->get('resources', []); $entities = collect([]); $requestedRelations = $this->relationsResolver->requestedRelations($request); @@ -152,7 +154,9 @@ protected function batchUpdateWithTransaction(Request $request) $this->performUpdate( $request, $entity, - $request->input("resources.{$entity->{$this->keyName()}}") + config('orion.use_validated') + ? $request->validated("resources.{$entity->{$this->keyName()}}") + : $request->input("resources.{$entity->{$this->keyName()}}") ); $this->beforeUpdateFresh($request, $entity); diff --git a/src/Concerns/HandlesStandardOperations.php b/src/Concerns/HandlesStandardOperations.php index 4b1e15a2..276d6372 100644 --- a/src/Concerns/HandlesStandardOperations.php +++ b/src/Concerns/HandlesStandardOperations.php @@ -187,7 +187,9 @@ protected function storeWithTransaction(Request $request) $this->performStore( $request, $entity, - $request->all() + config('orion.use_validated') + ? $request->validated() + : $request->all() ); $beforeStoreFreshResult = $this->beforeStoreFresh($request, $entity); @@ -432,7 +434,9 @@ protected function updateWithTransaction(Request $request, $key) $this->performUpdate( $request, $entity, - $request->all() + config('orion.use_validated') + ? $request->validated() + : $request->all() ); $beforeUpdateFreshResult = $this->beforeUpdateFresh($request, $entity);