Skip to content

Commit

Permalink
Adds use_validated config
Browse files Browse the repository at this point in the history
  • Loading branch information
alkin committed Jul 26, 2022
1 parent 10de4de commit cffffd8
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 12 deletions.
2 changes: 2 additions & 0 deletions config/orion.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,6 @@
*/
'max_nested_depth' => 1,
],

'use_validated' => false,
];
24 changes: 20 additions & 4 deletions src/Concerns/HandlesRelationManyToManyOperations.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
);

Expand Down Expand Up @@ -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)) {
Expand Down Expand Up @@ -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)
);

Expand Down Expand Up @@ -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)) {
Expand Down
8 changes: 6 additions & 2 deletions src/Concerns/HandlesRelationStandardBatchOperations.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
8 changes: 6 additions & 2 deletions src/Concerns/HandlesRelationStandardOperations.php
Original file line number Diff line number Diff line change
Expand Up @@ -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', [])
);

Expand Down Expand Up @@ -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', [])
);

Expand Down
8 changes: 6 additions & 2 deletions src/Concerns/HandlesStandardBatchOperations.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
8 changes: 6 additions & 2 deletions src/Concerns/HandlesStandardOperations.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit cffffd8

Please sign in to comment.