Skip to content

Commit

Permalink
make the config global
Browse files Browse the repository at this point in the history
  • Loading branch information
pxpm committed Jan 14, 2024
1 parent e539a61 commit 74644d2
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/app/Library/CrudPanel/Traits/Create.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public function create($input)
{
[$directInputs, $relationInputs] = $this->splitInputIntoDirectAndRelations($input);

if ($this->get('create.useDatabaseTransactions')) {
if ($this->get('create.useDatabaseTransactions') ?? config('backpack.base.useDatabaseTransactions', false)) {
return DB::transaction(fn () => $this->createModelAndRelations($directInputs, $relationInputs));
}

Expand Down
2 changes: 1 addition & 1 deletion src/app/Library/CrudPanel/Traits/Update.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public function update($id, $input)
$item = $this->model->findOrFail($id);

[$directInputs, $relationInputs] = $this->splitInputIntoDirectAndRelations($input);
if ($this->get('update.useDatabaseTransactions')) {
if ($this->get('update.useDatabaseTransactions') ?? config('backpack.base.useDatabaseTransactions', false)) {
return DB::transaction(fn () => $this->updateModelAndRelations($item, $directInputs, $relationInputs));
}

Expand Down
11 changes: 11 additions & 0 deletions src/config/backpack/base.php
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,17 @@
// You can rename this disk here. Default: root
'root_disk_name' => 'root',

/*
|--------------------------------------------------------------------------
| Application
|--------------------------------------------------------------------------
*/

// Should we use DB transactions when executing multiple queries? For example when creating an entry and it's relationships.
// By wrapping in a database transaction you ensure that either all queries went ok, or if some failed the whole process
// is rolled back and considered failed. This is a good setting for data integrity.
'useDatabaseTransactions' => false,

/*
|--------------------------------------------------------------------------
| Backpack Token Username
Expand Down
3 changes: 0 additions & 3 deletions src/config/backpack/operations/create.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,6 @@
// Should we warn a user before leaving the page with unsaved changes?
'warnBeforeLeaving' => false,

// Should the create process (queries to insert the entry and it's relationships) be wrapped in a transaction?
'useDatabaseTransactions' => false,

// Before saving the entry, how would you like the request to be stripped?
// - false - use Backpack's default (ONLY save inputs that have fields)
// - invokable class - custom stripping (the return should be an array with input names)
Expand Down
3 changes: 0 additions & 3 deletions src/config/backpack/operations/update.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,6 @@
// Should we warn a user before leaving the page with unsaved changes?
'warnBeforeLeaving' => false,

// Should the update process (queries to update the entry and it's relationships) be wrapped in a transaction?
'useDatabaseTransactions' => false,

// Before saving the entry, how would you like the request to be stripped?
// - false - use Backpack's default (ONLY save inputs that have fields)
// - invokable class - custom stripping (the return should be an array with input names)
Expand Down

0 comments on commit 74644d2

Please sign in to comment.