Skip to content

Commit a06d04e

Browse files
authored
Merge pull request #4505 from Laravel-Backpack/add-invokable-to-stripped-request
add invokable support to strippedRequest
2 parents 8a851d4 + dd764d2 commit a06d04e

File tree

3 files changed

+18
-23
lines changed

3 files changed

+18
-23
lines changed

src/app/Library/CrudPanel/Traits/Fields.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -479,6 +479,15 @@ public function getStrippedSaveRequest($request)
479479
{
480480
$setting = $this->getOperationSetting('strippedRequest');
481481

482+
// if an invokable class was passed
483+
// eg. \App\Http\Requests\BackpackStrippedRequest
484+
if (class_exists($setting)) {
485+
$setting = new $setting();
486+
487+
return is_callable($setting) ? $setting($request) : abort(500, get_class($setting).' is not invokable.');
488+
}
489+
490+
// if a closure was passed
482491
if (is_callable($setting)) {
483492
return $setting($request);
484493
}

src/config/backpack/operations/create.php

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -35,15 +35,8 @@
3535
// Should we warn a user before leaving the page with unsaved changes?
3636
'warnBeforeLeaving' => false,
3737

38-
/**
39-
* Before saving the entry, how would you like the request to be stripped?
40-
* - false - fall back to Backpack's default (ONLY save inputs that have fields)
41-
* - closure - process your own request (example removes all inputs that begin with underscode).
42-
*
43-
* @param \Illuminate\Http\Request $request
44-
* @return array
45-
*/
46-
// 'strippedRequest' => (function ($request) {
47-
// return $request->except('_token', '_method', '_http_referrer', '_current_tab', '_save_action');
48-
// }),
38+
// Before saving the entry, how would you like the request to be stripped?
39+
// - false - use Backpack's default (ONLY save inputs that have fields)
40+
// - invokable class - custom stripping (the return should be an array with input names)
41+
// 'strippedRequest' => App\Http\Requests\StripBackpackRequest::class,
4942
];

src/config/backpack/operations/update.php

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
return [
1010
// Define the size/looks of the content div for all CRUDs
1111
// To override per view use $this->crud->setEditContentClass('class-string')
12-
'contentClass' => 'col-md-8 bold-labels',
12+
'contentClass' => 'col-md-8 bold-labels',
1313

1414
// When using tabbed forms (create & update), what kind of tabs would you like?
1515
'tabsType' => 'horizontal', //options: horizontal, vertical
@@ -35,15 +35,8 @@
3535
// Should we warn a user before leaving the page with unsaved changes?
3636
'warnBeforeLeaving' => false,
3737

38-
/**
39-
* Before saving the entry, how would you like the request to be stripped?
40-
* - false - fall back to Backpack's default (ONLY save inputs that have fields)
41-
* - closure - process your own request (example removes all inputs that begin with underscode).
42-
*
43-
* @param \Illuminate\Http\Request $request
44-
* @return array
45-
*/
46-
// 'strippedRequest' => (function ($request) {
47-
// return $request->except('_token', '_method', '_http_referrer', '_current_tab', '_save_action');
48-
// }),
38+
// Before saving the entry, how would you like the request to be stripped?
39+
// - false - use Backpack's default (ONLY save inputs that have fields)
40+
// - invokable class - custom stripping (the return should be an array with input names)
41+
// 'strippedRequest' => App\Http\Requests\StripBackpackRequest::class,
4942
];

0 commit comments

Comments
 (0)