From 2248e81dd69934f3ce3019b6ff228d574ee5176b Mon Sep 17 00:00:00 2001 From: Cristian Tabacitu Date: Sat, 4 Dec 2021 13:20:08 +0200 Subject: [PATCH 1/2] fixes #3789 by passing the to the saving --- src/app/Http/Controllers/Operations/CreateOperation.php | 2 +- src/app/Http/Controllers/Operations/UpdateOperation.php | 3 ++- src/app/Library/CrudPanel/Traits/Fields.php | 9 ++++++--- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/app/Http/Controllers/Operations/CreateOperation.php b/src/app/Http/Controllers/Operations/CreateOperation.php index c27fc5affe..bed7fa841c 100644 --- a/src/app/Http/Controllers/Operations/CreateOperation.php +++ b/src/app/Http/Controllers/Operations/CreateOperation.php @@ -76,7 +76,7 @@ public function store() $request = $this->crud->validateRequest(); // insert item in the db - $item = $this->crud->create($this->crud->getStrippedSaveRequest()); + $item = $this->crud->create($this->crud->getStrippedSaveRequest($request)); $this->data['entry'] = $this->crud->entry = $item; // show a success message diff --git a/src/app/Http/Controllers/Operations/UpdateOperation.php b/src/app/Http/Controllers/Operations/UpdateOperation.php index d176d51083..01b4b35bd2 100644 --- a/src/app/Http/Controllers/Operations/UpdateOperation.php +++ b/src/app/Http/Controllers/Operations/UpdateOperation.php @@ -89,10 +89,11 @@ public function update() // execute the FormRequest authorization and validation, if one is required $request = $this->crud->validateRequest(); + // update the row in the db $item = $this->crud->update( $request->get($this->crud->model->getKeyName()), - $this->crud->getStrippedSaveRequest() + $this->crud->getStrippedSaveRequest($request) ); $this->data['entry'] = $this->crud->entry = $item; diff --git a/src/app/Library/CrudPanel/Traits/Fields.php b/src/app/Library/CrudPanel/Traits/Fields.php index 56ef42c7bf..53e4eddf17 100644 --- a/src/app/Library/CrudPanel/Traits/Fields.php +++ b/src/app/Library/CrudPanel/Traits/Fields.php @@ -426,16 +426,19 @@ public function getAllFieldNames() /** * Returns the request without anything that might have been maliciously inserted. * Only specific field names that have been introduced with addField() are kept in the request. + * + * @param \Illuminate\Http\Request $request + * @return array */ - public function getStrippedSaveRequest() + public function getStrippedSaveRequest($request) { $setting = $this->getOperationSetting('strippedRequest'); if (is_callable($setting)) { - return $setting($this->getRequest()); + return $setting($request); } - return $this->getRequest()->only($this->getAllFieldNames()); + return $request->only($this->getAllFieldNames()); } /** From f683950bd5d2d1dd66caf5abec9bd6e7a4146f83 Mon Sep 17 00:00:00 2001 From: Cristian Tabacitu Date: Sat, 4 Dec 2021 11:20:25 +0000 Subject: [PATCH 2/2] Apply fixes from StyleCI [ci skip] [skip ci] --- src/BackpackServiceProvider.php | 2 +- src/app/Library/CrudPanel/Traits/Fields.php | 2 +- src/config/backpack/crud.php | 2 +- src/config/backpack/operations/create.php | 18 +++++++++--------- src/config/backpack/operations/list.php | 2 +- src/config/backpack/operations/reorder.php | 2 +- src/config/backpack/operations/show.php | 2 +- src/config/backpack/operations/update.php | 18 +++++++++--------- 8 files changed, 24 insertions(+), 24 deletions(-) diff --git a/src/BackpackServiceProvider.php b/src/BackpackServiceProvider.php index 113f1c0090..4bed0a47f7 100644 --- a/src/BackpackServiceProvider.php +++ b/src/BackpackServiceProvider.php @@ -242,7 +242,7 @@ protected function mergeConfigFromOperationsDirectory() $operationConfigs = scandir(__DIR__.'/config/backpack/operations/'); $operationConfigs = array_diff($operationConfigs, ['.', '..']); - if (!count($operationConfigs)) { + if (! count($operationConfigs)) { return; } diff --git a/src/app/Library/CrudPanel/Traits/Fields.php b/src/app/Library/CrudPanel/Traits/Fields.php index 53e4eddf17..58275523d3 100644 --- a/src/app/Library/CrudPanel/Traits/Fields.php +++ b/src/app/Library/CrudPanel/Traits/Fields.php @@ -427,7 +427,7 @@ public function getAllFieldNames() * Returns the request without anything that might have been maliciously inserted. * Only specific field names that have been introduced with addField() are kept in the request. * - * @param \Illuminate\Http\Request $request + * @param \Illuminate\Http\Request $request * @return array */ public function getStrippedSaveRequest($request) diff --git a/src/config/backpack/crud.php b/src/config/backpack/crud.php index e799e7f3a0..8067cc8b35 100644 --- a/src/config/backpack/crud.php +++ b/src/config/backpack/crud.php @@ -1,7 +1,7 @@ false, - /** - * 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 - */ +/** + * 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'); // }), diff --git a/src/config/backpack/operations/list.php b/src/config/backpack/operations/list.php index 0bc8e8678c..e860fac259 100644 --- a/src/config/backpack/operations/list.php +++ b/src/config/backpack/operations/list.php @@ -1,7 +1,7 @@ false, - /** - * 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 - */ +/** + * 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'); // }),