Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[4.2][Feature] Custom save request stripping #3987

Merged
merged 3 commits into from
Dec 6, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/BackpackServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ protected function mergeConfigFromOperationsDirectory()
$operationConfigs = scandir(__DIR__.'/config/backpack/operations/');
$operationConfigs = array_diff($operationConfigs, ['.', '..']);

if (!count($operationConfigs)) {
if (! count($operationConfigs)) {
return;
}

Expand Down
9 changes: 3 additions & 6 deletions src/app/Library/CrudPanel/Traits/Fields.php
Original file line number Diff line number Diff line change
Expand Up @@ -429,13 +429,10 @@ public function getAllFieldNames()
*/
public function getStrippedSaveRequest()
{
$setting = $this->getOperationSetting('saveAllInputsExcept');
if ($setting == false || $setting == null) {
return $this->getRequest()->only($this->getAllFieldNames());
}
$setting = $this->getOperationSetting('strippedRequest');

if (is_array($setting)) {
return $this->getRequest()->except($this->getOperationSetting('saveAllInputsExcept'));
if (is_callable($setting)) {
return $setting($this->getRequest());
}

return $this->getRequest()->only($this->getAllFieldNames());
Expand Down
2 changes: 1 addition & 1 deletion src/config/backpack/crud.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php

/**
* Backpack\CRUD preferences
* Backpack\CRUD preferences.
*/

return [
Expand Down
18 changes: 12 additions & 6 deletions src/config/backpack/operations/create.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php

/**
* Configurations for Backpack's CreateOperation
* Configurations for Backpack's CreateOperation.
*
* @see https://backpackforlaravel.com/docs/crud-operation-create
*/
Expand Down Expand Up @@ -35,9 +35,15 @@
// Should we warn a user before leaving the page with unsaved changes?
'warnBeforeLeaving' => false,

// Before saving the entry, how would you like the request to be stripped?
// - false - ONLY save inputs that have fields (safest)
// - [x, y, z] - save ALL inputs, EXCEPT the ones given in this array
'saveAllInputsExcept' => false,
// 'saveAllInputsExcept' => ['_token', '_method', '_http_referrer', '_current_tab', '_save_action'],
/**
* Before saving the entry, how would you like the request to be stripped?
* - false - fall back to Backpack's default (ONLY save inputs that have fields)
* - closure - process your own request (example removes all inputs that begin with underscode).
*
* @param \Illuminate\Http\Request $request
* @return array
*/
// 'strippedRequest' => (function ($request) {
// return $request->except('_token', '_method', '_http_referrer', '_current_tab', '_save_action');
// }),
];
2 changes: 1 addition & 1 deletion src/config/backpack/operations/list.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php

/**
* Configurations for Backpack's ListOperation
* Configurations for Backpack's ListOperation.
*
* @see https://backpackforlaravel.com/docs/crud-operation-list
*/
Expand Down
2 changes: 1 addition & 1 deletion src/config/backpack/operations/reorder.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php

/**
* Configurations for Backpack's ReorderOperation
* Configurations for Backpack's ReorderOperation.
*
* @see https://backpackforlaravel.com/docs/crud-operation-reorder
*/
Expand Down
2 changes: 1 addition & 1 deletion src/config/backpack/operations/show.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php

/**
* Configurations for Backpack's ShowOperation
* Configurations for Backpack's ShowOperation.
*
* @see https://backpackforlaravel.com/docs/crud-operation-show
*/
Expand Down
18 changes: 12 additions & 6 deletions src/config/backpack/operations/update.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php

/**
* Configurations for Backpack's UpdateOperation
* Configurations for Backpack's UpdateOperation.
*
* @see https://backpackforlaravel.com/docs/crud-operation-update
*/
Expand Down Expand Up @@ -35,9 +35,15 @@
// Should we warn a user before leaving the page with unsaved changes?
'warnBeforeLeaving' => false,

// Before saving the entry, how would you like the request to be stripped?
// - false - Save ONLY inputs that have a field (safest, default);
// - [x, y, z] - Save ALL inputs, EXCEPT the ones given in this array;
'saveAllInputsExcept' => false,
// 'saveAllInputsExcept' => ['_token', '_method', '_http_referrer', '_current_tab', '_save_action'],
/**
* Before saving the entry, how would you like the request to be stripped?
* - false - fall back to Backpack's default (ONLY save inputs that have fields)
* - closure - process your own request (example removes all inputs that begin with underscode).
*
* @param \Illuminate\Http\Request $request
* @return array
*/
// 'strippedRequest' => (function ($request) {
// return $request->except('_token', '_method', '_http_referrer', '_current_tab', '_save_action');
// }),
];