diff --git a/config/orion.php b/config/orion.php index e0aba7a2..ad94b01b 100644 --- a/config/orion.php +++ b/config/orion.php @@ -28,4 +28,7 @@ ['url' => env('APP_URL').'/api', 'description' => 'Default Environment'], ], ], + 'transactions' => [ + 'enabled' => false, + ], ]; diff --git a/src/Concerns/HandlesRelationManyToManyOperations.php b/src/Concerns/HandlesRelationManyToManyOperations.php index ccf325c8..37211138 100644 --- a/src/Concerns/HandlesRelationManyToManyOperations.php +++ b/src/Concerns/HandlesRelationManyToManyOperations.php @@ -13,13 +13,32 @@ trait HandlesRelationManyToManyOperations { /** - * Attach resource to the relation. + * Attach resource to the relation in a transaction-safe way. * * @param Request $request * @param int|string $parentKey * @return JsonResponse */ public function attach(Request $request, $parentKey) + { + try { + $this->startTransaction(); + $result = $this->attachWithTransaction($request, $parentKey); + $this->commitTransaction(); + return $result; + } catch (\Exception $exception) { + $this->rollbackTransactionAndRaise($exception); + } + } + + /** + * Attach resource to the relation. + * + * @param Request $request + * @param int|string $parentKey + * @return JsonResponse + */ + protected function attachWithTransaction(Request $request, $parentKey) { $parentQuery = $this->buildAttachParentFetchQuery($request, $parentKey); $parentEntity = $this->runAttachParentFetchQuery($request, $parentQuery, $parentKey); @@ -215,13 +234,32 @@ protected function afterAttach(Request $request, Model $parentEntity, array &$at } /** - * Detach resource to the relation. + * Detach resource to the relation in a transaction-safe way. * * @param Request $request * @param int|string $parentKey * @return JsonResponse */ public function detach(Request $request, $parentKey) + { + try { + $this->startTransaction(); + $result = $this->detachWithTransaction($request, $parentKey); + $this->commitTransaction(); + return $result; + } catch (\Exception $exception) { + $this->rollbackTransactionAndRaise($exception); + } + } + + /** + * Detach resource to the relation. + * + * @param Request $request + * @param int|string $parentKey + * @return JsonResponse + */ + protected function detachWithTransaction(Request $request, $parentKey) { $parentQuery = $this->buildDetachParentFetchQuery($request, $parentKey); $parentEntity = $this->runDetachParentFetchQuery($request, $parentQuery, $parentKey); @@ -315,13 +353,32 @@ protected function afterDetach(Request $request, Model $parentEntity, array &$de } /** - * Sync relation resources. + * Sync relation resources in a transaction-safe way. * * @param Request $request * @param int|string $parentKey * @return JsonResponse */ public function sync(Request $request, $parentKey) + { + try { + $this->startTransaction(); + $result = $this->syncWithTransaction($request, $parentKey); + $this->commitTransaction(); + return $result; + } catch (\Exception $exception) { + $this->rollbackTransactionAndRaise($exception); + } + } + + /** + * Sync relation resources. + * + * @param Request $request + * @param int|string $parentKey + * @return JsonResponse + */ + protected function syncWithTransaction(Request $request, $parentKey) { $parentQuery = $this->buildSyncParentFetchQuery($request, $parentKey); $parentEntity = $this->runSyncParentFetchQuery($request, $parentQuery, $parentKey); @@ -422,13 +479,32 @@ protected function afterSync(Request $request, Model $parentEntity, array &$sync } /** - * Toggle relation resources. + * Toggle relation resources in a transaction-safe way. * * @param Request $request * @param int|string $parentKey * @return JsonResponse */ public function toggle(Request $request, $parentKey) + { + try { + $this->startTransaction(); + $result = $this->toggleWithTransaction($request, $parentKey); + $this->commitTransaction(); + return $result; + } catch (\Exception $exception) { + $this->rollbackTransactionAndRaise($exception); + } + } + + /** + * Toggle relation resources. + * + * @param Request $request + * @param int|string $parentKey + * @return JsonResponse + */ + protected function toggleWithTransaction(Request $request, $parentKey) { $parentQuery = $this->buildToggleParentFetchQuery($request, $parentKey); $parentEntity = $this->runToggleParentFetchQuery($request, $parentQuery, $parentKey); @@ -516,7 +592,7 @@ protected function afterToggle(Request $request, Model $parentEntity, array &$to } /** - * Update relation resource pivot. + * Update relation resource pivot in a transaction-safe wqy. * * @param Request $request * @param int|string $parentKey @@ -524,6 +600,26 @@ protected function afterToggle(Request $request, Model $parentEntity, array &$to * @return JsonResponse */ public function updatePivot(Request $request, $parentKey, $relatedKey) + { + try { + $this->startTransaction(); + $result = $this->updatePivotWithTransaction($request, $parentKey, $relatedKey); + $this->commitTransaction(); + return $result; + } catch (\Exception $exception) { + $this->rollbackTransactionAndRaise($exception); + } + } + + /** + * Update relation resource pivot. + * + * @param Request $request + * @param int|string $parentKey + * @param int|string $relatedKey + * @return JsonResponse + */ + protected function updatePivotWithTransaction(Request $request, $parentKey, $relatedKey) { $parentQuery = $this->buildUpdatePivotParentFetchQuery($request, $parentKey); $parentEntity = $this->runUpdatePivotParentFetchQuery($request, $parentQuery, $parentKey); diff --git a/src/Concerns/HandlesRelationOneToManyOperations.php b/src/Concerns/HandlesRelationOneToManyOperations.php index bd096f3e..25d105ac 100644 --- a/src/Concerns/HandlesRelationOneToManyOperations.php +++ b/src/Concerns/HandlesRelationOneToManyOperations.php @@ -11,13 +11,32 @@ trait HandlesRelationOneToManyOperations { /** - * Associates resource with another resource. + * Associates resource with another resource in a transaction-safe way. * * @param Request $request * @param int|string $parentKey * @return Resource */ public function associate(Request $request, $parentKey) + { + try { + $this->startTransaction(); + $result = $this->associateWithTransaction($request, $parentKey); + $this->commitTransaction(); + return $result; + } catch (\Exception $exception) { + $this->rollbackTransactionAndRaise($exception); + } + } + + /** + * Associates resource with another resource. + * + * @param Request $request + * @param int|string $parentKey + * @return Resource + */ + protected function associateWithTransaction(Request $request, $parentKey) { $parentQuery = $this->buildAssociateParentFetchQuery($request, $parentKey); $parentEntity = $this->runAssociateParentFetchQuery($request, $parentQuery, $parentKey); @@ -143,7 +162,7 @@ protected function afterAssociate(Request $request, Model $parentEntity, Model $ } /** - * Disassociates resource from another resource. + * Disassociates resource from another resource in a transaction-safe way. * * @param Request $request * @param int|string $parentKey @@ -151,6 +170,26 @@ protected function afterAssociate(Request $request, Model $parentEntity, Model $ * @return Resource */ public function dissociate(Request $request, $parentKey, $relatedKey) + { + try { + $this->startTransaction(); + $result = $this->dissociateWithTransaction($request, $parentKey, $relatedKey); + $this->commitTransaction(); + return $result; + } catch (\Exception $exception) { + $this->rollbackTransactionAndRaise($exception); + } + } + + /** + * Disassociates resource from another resource. + * + * @param Request $request + * @param int|string $parentKey + * @param int|string $relatedKey + * @return Resource + */ + protected function dissociateWithTransaction(Request $request, $parentKey, $relatedKey) { $parentQuery = $this->buildDissociateParentFetchQuery($request, $parentKey); $parentEntity = $this->runDissociateParentFetchQuery($request, $parentQuery, $parentKey); diff --git a/src/Concerns/HandlesRelationStandardBatchOperations.php b/src/Concerns/HandlesRelationStandardBatchOperations.php index 00da6bdb..df569236 100644 --- a/src/Concerns/HandlesRelationStandardBatchOperations.php +++ b/src/Concerns/HandlesRelationStandardBatchOperations.php @@ -14,13 +14,32 @@ trait HandlesRelationStandardBatchOperations { /** - * Create a batch of new relation resources. + * Create a batch of new relation resources in a transaction-safe way. * * @param Request $request * @param int|string $parentKey * @return CollectionResource */ public function batchStore(Request $request, $parentKey) + { + try { + $this->startTransaction(); + $result = $this->batchStoreWithTransaction($request, $parentKey); + $this->commitTransaction(); + return $result; + } catch (\Exception $exception) { + $this->rollbackTransactionAndRaise($exception); + } + } + + /** + * Create a batch of new relation resources. + * + * @param Request $request + * @param int|string $parentKey + * @return CollectionResource + */ + protected function batchStoreWithTransaction(Request $request, $parentKey) { $resourceModelClass = $this->resolveResourceModelClass(); @@ -133,13 +152,32 @@ protected function afterBatchStore(Request $request, Model $parentEntity, Collec } /** - * Updates a batch of relation resources. + * Updates a batch of relation resources in a transaction-safe way. * * @param Request $request * @param int|string $parentKey * @return CollectionResource */ public function batchUpdate(Request $request, $parentKey) + { + try { + $this->startTransaction(); + $result = $this->batchUpdateWithTransaction($request, $parentKey); + $this->commitTransaction(); + return $result; + } catch (\Exception $exception) { + $this->rollbackTransactionAndRaise($exception); + } + } + + /** + * Updates a batch of relation resources. + * + * @param Request $request + * @param int|string $parentKey + * @return CollectionResource + */ + protected function batchUpdateWithTransaction(Request $request, $parentKey) { $parentQuery = $this->buildBatchUpdateParentFetchQuery($request, $parentKey); $parentEntity = $this->runBatchUpdateParentFetchQuery($request, $parentQuery, $parentKey); @@ -309,7 +347,7 @@ protected function afterBatchUpdate(Request $request, Model $parentEntity, Colle } /** - * Deletes a batch of relation resources. + * Deletes a batch of relation resources in a transaction-safe way. * * @param Request $request * @param int|string $parentKey @@ -317,6 +355,26 @@ protected function afterBatchUpdate(Request $request, Model $parentEntity, Colle * @throws Exception */ public function batchDestroy(Request $request, $parentKey) + { + try { + $this->startTransaction(); + $result = $this->batchDestroyWithTransaction($request, $parentKey); + $this->commitTransaction(); + return $result; + } catch (\Exception $exception) { + $this->rollbackTransactionAndRaise($exception); + } + } + + /** + * Deletes a batch of relation resources. + * + * @param Request $request + * @param int|string $parentKey + * @return CollectionResource + * @throws Exception + */ + protected function batchDestroyWithTransaction(Request $request, $parentKey) { $parentQuery = $this->buildBatchDestroyParentFetchQuery($request, $parentKey); $parentEntity = $this->runBatchDestroyParentFetchQuery($request, $parentQuery, $parentKey); @@ -458,7 +516,7 @@ protected function afterBatchDestroy(Request $request, Model $parentEntity, Coll } /** - * Restores a batch of relation resources. + * Restores a batch of relation resources in a transaction-safe way. * * @param Request $request * @param int|string $parentKey @@ -466,6 +524,26 @@ protected function afterBatchDestroy(Request $request, Model $parentEntity, Coll * @throws Exception */ public function batchRestore(Request $request, $parentKey) + { + try { + $this->startTransaction(); + $result = $this->batchRestoreWithTransaction($request, $parentKey); + $this->commitTransaction(); + return $result; + } catch (\Exception $exception) { + $this->rollbackTransactionAndRaise($exception); + } + } + + /** + * Restores a batch of relation resources. + * + * @param Request $request + * @param int|string $parentKey + * @return CollectionResource + * @throws Exception + */ + protected function batchRestoreWithTransaction(Request $request, $parentKey) { $parentQuery = $this->buildBatchRestoreParentFetchQuery($request, $parentKey); $parentEntity = $this->runBatchRestoreParentFetchQuery($request, $parentQuery, $parentKey); diff --git a/src/Concerns/HandlesRelationStandardOperations.php b/src/Concerns/HandlesRelationStandardOperations.php index 881e8351..23e17405 100644 --- a/src/Concerns/HandlesRelationStandardOperations.php +++ b/src/Concerns/HandlesRelationStandardOperations.php @@ -3,22 +3,23 @@ namespace Orion\Concerns; use Exception; -use Illuminate\Contracts\Pagination\Paginator; +use Illuminate\Support\Arr; +use InvalidArgumentException; +use Orion\Http\Requests\Request; +use Orion\Http\Resources\Resource; +use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Builder; use Illuminate\Database\Eloquent\Collection; -use Illuminate\Database\Eloquent\Model; -use Illuminate\Database\Eloquent\Relations\BelongsTo; -use Illuminate\Database\Eloquent\Relations\BelongsToMany; +use Orion\Http\Resources\CollectionResource; +use Illuminate\Database\Eloquent\SoftDeletes; +use Illuminate\Contracts\Pagination\Paginator; use Illuminate\Database\Eloquent\Relations\HasOne; use Illuminate\Database\Eloquent\Relations\MorphOne; -use Illuminate\Database\Eloquent\Relations\MorphToMany; use Illuminate\Database\Eloquent\Relations\Relation; -use Illuminate\Database\Eloquent\SoftDeletes; -use Illuminate\Support\Arr; -use InvalidArgumentException; -use Orion\Http\Requests\Request; -use Orion\Http\Resources\CollectionResource; -use Orion\Http\Resources\Resource; +use Illuminate\Database\Eloquent\Relations\BelongsTo; +use Illuminate\Database\Eloquent\Relations\MorphToMany; +use Illuminate\Database\Eloquent\Relations\BelongsToMany; +use Illuminate\Database\Eloquent\Relations\HasOneThrough; trait HandlesRelationStandardOperations { @@ -230,6 +231,25 @@ public function search(Request $request, $parentKey) * @return Resource */ public function store(Request $request, $parentKey) + { + try { + $this->startTransaction(); + $result = $this->storeWithTransaction($request, $parentKey); + $this->commitTransaction(); + return $result; + } catch (\Exception $exception) { + $this->rollbackTransactionAndRaise($exception); + } + } + + /** + * Create new relation resource. + * + * @param Request $request + * @param int|string $parentKey + * @return Resource + */ + protected function storeWithTransaction(Request $request, $parentKey) { $resourceModelClass = $this->resolveResourceModelClass(); @@ -556,7 +576,7 @@ protected function afterShow(Request $request, Model $parentEntity, Model $entit } /** - * Update a relation resource. + * Update a relation resource in a transaction-safe way. * * @param Request $request * @param int|string $parentKey @@ -564,6 +584,26 @@ protected function afterShow(Request $request, Model $parentEntity, Model $entit * @return Resource */ public function update(Request $request, $parentKey, $relatedKey = null) + { + try { + $this->startTransaction(); + $result = $this->updateWithTransaction($request, $parentKey, $relatedKey); + $this->commitTransaction(); + return $result; + } catch (\Exception $exception) { + $this->rollbackTransactionAndRaise($exception); + } + } + + /** + * Update a relation resource. + * + * @param Request $request + * @param int|string $parentKey + * @param int|string|null $relatedKey + * @return Resource + */ + protected function updateWithTransaction(Request $request, $parentKey, $relatedKey = null) { $parentQuery = $this->buildUpdateParentFetchQuery($request, $parentKey); $parentEntity = $this->runUpdateParentFetchQuery($request, $parentQuery, $parentKey); @@ -734,6 +774,27 @@ protected function afterUpdate(Request $request, Model $parentEntity, Model $ent * @throws Exception */ public function destroy(Request $request, $parentKey, $relatedKey = null) + { + try { + $this->startTransaction(); + $result = $this->destroyWithTransaction($request, $parentKey, $relatedKey); + $this->commitTransaction(); + return $result; + } catch (\Exception $exception) { + $this->rollbackTransactionAndRaise($exception); + } + } + + /** + * Delete a relation resource. + * + * @param Request $request + * @param int|string $parentKey + * @param int|string|null $relatedKey + * @return Resource + * @throws Exception + */ + protected function destroyWithTransaction(Request $request, $parentKey, $relatedKey = null) { $parentQuery = $this->buildDestroyParentFetchQuery($request, $parentKey); $parentEntity = $this->runDestroyParentFetchQuery($request, $parentQuery, $parentKey); @@ -896,7 +957,7 @@ protected function afterDestroy(Request $request, Model $parentEntity, Model $en } /** - * Restores a previously deleted relation resource. + * Restores a previously deleted relation resource in a transaction-save way. * * @param Request $request * @param int|string $parentKey @@ -904,6 +965,26 @@ protected function afterDestroy(Request $request, Model $parentEntity, Model $en * @return Resource */ public function restore(Request $request, $parentKey, $relatedKey = null) + { + try { + $this->startTransaction(); + $result = $this->restoreWithTransaction($request, $parentKey, $relatedKey); + $this->commitTransaction(); + return $result; + } catch (\Exception $exception) { + $this->rollbackTransactionAndRaise($exception); + } + } + + /** + * Restores a previously deleted relation resource. + * + * @param Request $request + * @param int|string $parentKey + * @param int|string|null $relatedKey + * @return Resource + */ + protected function restoreWithTransaction(Request $request, $parentKey, $relatedKey = null) { $parentQuery = $this->buildRestoreParentFetchQuery($request, $parentKey); $parentEntity = $this->runRestoreParentFetchQuery($request, $parentQuery, $parentKey); diff --git a/src/Concerns/HandlesStandardBatchOperations.php b/src/Concerns/HandlesStandardBatchOperations.php index 00712e9d..2ab002c5 100644 --- a/src/Concerns/HandlesStandardBatchOperations.php +++ b/src/Concerns/HandlesStandardBatchOperations.php @@ -12,12 +12,30 @@ trait HandlesStandardBatchOperations { /** - * Creates a batch of new resources. + * Creates a batch of new resources in a transaction-safe way. * * @param Request $request * @return CollectionResource */ public function batchStore(Request $request) + { + try { + $this->startTransaction(); + $result = $this->batchStoreWithTransaction($request); + $this->commitTransaction(); + return $result; + } catch (\Exception $exception) { + $this->rollbackTransactionAndRaise($exception); + } + } + + /** + * Creates a batch of new resources. + * + * @param Request $request + * @return CollectionResource + */ + protected function batchStoreWithTransaction(Request $request) { $beforeHookResult = $this->beforeBatchStore($request); if ($this->hookResponds($beforeHookResult)) { @@ -87,12 +105,30 @@ protected function afterBatchStore(Request $request, Collection $entities) } /** - * Update a batch of resources. + * Update a batch of resources in a transaction-safe way. * * @param Request $request * @return CollectionResource */ public function batchUpdate(Request $request) + { + try { + $this->startTransaction(); + $result = $this->batchUpdateWithTransaction($request); + $this->commitTransaction(); + return $result; + } catch (\Exception $exception) { + $this->rollbackTransactionAndRaise($exception); + } + } + + /** + * Update a batch of resources. + * + * @param Request $request + * @return CollectionResource + */ + protected function batchUpdateWithTransaction(Request $request) { $beforeHookResult = $this->beforeBatchUpdate($request); if ($this->hookResponds($beforeHookResult)) { @@ -209,13 +245,32 @@ protected function afterBatchUpdate(Request $request, Collection $entities) } /** - * Deletes a batch of resources. + * Deletes a batch of resources in a transaction-safe way. * * @param Request $request * @return CollectionResource * @throws Exception */ public function batchDestroy(Request $request) + { + try { + $this->startTransaction(); + $result = $this->batchDestroyWithTransaction($request); + $this->commitTransaction(); + return $result; + } catch (\Exception $exception) { + $this->rollbackTransactionAndRaise($exception); + } + } + + /** + * Deletes a batch of resources. + * + * @param Request $request + * @return CollectionResource + * @throws Exception + */ + protected function batchDestroyWithTransaction(Request $request) { $beforeHookResult = $this->beforeBatchDestroy($request); if ($this->hookResponds($beforeHookResult)) { @@ -312,13 +367,32 @@ protected function afterBatchDestroy(Request $request, Collection $entities) } /** - * Restores a batch of resources. + * Restores a batch of resources in a transaction-safe way. * * @param Request $request * @return CollectionResource * @throws Exception */ public function batchRestore(Request $request) + { + try { + $this->startTransaction(); + $result = $this->batchRestoreWithTransaction($request); + $this->commitTransaction(); + return $result; + } catch (\Exception $exception) { + $this->rollbackTransactionAndRaise($exception); + } + } + + /** + * Restores a batch of resources. + * + * @param Request $request + * @return CollectionResource + * @throws Exception + */ + protected function batchRestoreWithTransaction(Request $request) { $beforeHookResult = $this->beforeBatchRestore($request); if ($this->hookResponds($beforeHookResult)) { diff --git a/src/Concerns/HandlesStandardOperations.php b/src/Concerns/HandlesStandardOperations.php index 2fbc5212..fad4446b 100644 --- a/src/Concerns/HandlesStandardOperations.php +++ b/src/Concerns/HandlesStandardOperations.php @@ -122,12 +122,30 @@ public function search(Request $request) } /** - * Creates new resource. + * Creates new resource in a transaction-safe way. * * @param Request $request * @return Resource */ public function store(Request $request) + { + try { + $this->startTransaction(); + $result = $this->storeWithTransaction($request); + $this->commitTransaction(); + return $result; + } catch (\Exception $exception) { + $this->rollbackTransactionAndRaise($exception); + } + } + + /** + * Creates new resource. + * + * @param Request $request + * @return Resource + */ + protected function storeWithTransaction(Request $request) { $resourceModelClass = $this->resolveResourceModelClass(); @@ -330,13 +348,32 @@ protected function afterShow(Request $request, Model $entity) } /** - * Updates a resource. + * Update a resource in a transaction-safe way. * * @param Request $request * @param int|string $key * @return Resource */ public function update(Request $request, $key) + { + try { + $this->startTransaction(); + $result = $this->updateWithTransaction($request, $key); + $this->commitTransaction(); + return $result; + } catch (\Exception $exception) { + $this->rollbackTransactionAndRaise($exception); + } + } + + /** + * Updates a resource. + * + * @param Request $request + * @param int|string $key + * @return Resource + */ + protected function updateWithTransaction(Request $request, $key) { $requestedRelations = $this->relationsResolver->requestedRelations($request); @@ -449,6 +486,26 @@ protected function afterUpdate(Request $request, Model $entity) * @throws Exception */ public function destroy(Request $request, $key) + { + try { + $this->startTransaction(); + $result = $this->destroyWithTransaction($request, $key); + $this->commitTransaction(); + return $result; + } catch (\Exception $exception) { + $this->rollbackTransactionAndRaise($exception); + } + } + + /** + * Deletes a resource. + * + * @param Request $request + * @param int|string $key + * @return Resource + * @throws Exception + */ + protected function destroyWithTransaction(Request $request, $key) { $softDeletes = $this->softDeletes($this->resolveResourceModelClass()); $forceDeletes = $this->forceDeletes($request, $softDeletes); @@ -566,7 +623,7 @@ protected function afterDestroy(Request $request, Model $entity) } /** - * Restore previously deleted resource. + * Restore previously deleted resource in a transaction-safe way. * * @param Request $request * @param int|string $key @@ -574,6 +631,26 @@ protected function afterDestroy(Request $request, Model $entity) * @throws Exception */ public function restore(Request $request, $key) + { + try { + $this->startTransaction(); + $result = $this->restoreWithTransaction($request, $key); + $this->commitTransaction(); + return $result; + } catch (\Exception $exception) { + $this->rollbackTransactionAndRaise($exception); + } + } + + /** + * Restore previously deleted resource. + * + * @param Request $request + * @param int|string $key + * @return Resource + * @throws Exception + */ + protected function restoreWithTransaction(Request $request, $key) { $requestedRelations = $this->relationsResolver->requestedRelations($request); diff --git a/src/Concerns/HandlesTransactions.php b/src/Concerns/HandlesTransactions.php new file mode 100644 index 00000000..ba30c650 --- /dev/null +++ b/src/Concerns/HandlesTransactions.php @@ -0,0 +1,78 @@ +transactionsAreEnabled() !== true) { + return; + } + + DB::beginTransaction(); + } + + /** + * Commit changes to database and finish database + * transaction + * + * @return void + */ + protected function commitTransaction(): void + { + if ($this->transactionsAreEnabled() !== true) { + return; + } + + DB::commit(); + } + + /** + * Rollback changes made to database and finish + * database transaction + * + * @return void + */ + protected function rollbackTransaction(): void + { + if ($this->transactionsAreEnabled() !== true) { + return; + } + + DB::rollBack(); + } + + /** + * Rollback changes made to database and finish + * database transaction and finally raise an exception + * + * @param \Exception $exception + * @return void + * + * @throws Exception + */ + protected function rollbackTransactionAndRaise(\Exception $exception): void + { + $this->rollbackTransaction(); + + throw $exception; + } + + /** + * Return configuration value + * + * @return boolean + */ + protected function transactionsAreEnabled(): bool + { + return (bool)config('orion.transactions.enabled', false); + } +} diff --git a/src/Http/Controllers/BaseController.php b/src/Http/Controllers/BaseController.php index 9ad945cc..07c67e11 100644 --- a/src/Http/Controllers/BaseController.php +++ b/src/Http/Controllers/BaseController.php @@ -11,6 +11,7 @@ use Illuminate\Support\Facades\Auth; use Orion\Concerns\BuildsResponses; use Orion\Concerns\HandlesAuthorization; +use Orion\Concerns\HandlesTransactions; use Orion\Concerns\InteractsWithBatchResources; use Orion\Concerns\InteractsWithHooks; use Orion\Concerns\InteractsWithSoftDeletes; @@ -32,7 +33,8 @@ abstract class BaseController extends \Illuminate\Routing\Controller InteractsWithHooks, InteractsWithSoftDeletes, InteractsWithBatchResources, - BuildsResponses; + BuildsResponses, + HandlesTransactions; /** * @var string $model