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

Make requests modifiable v2 #3988

Merged
merged 2 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
2 changes: 1 addition & 1 deletion src/app/Http/Controllers/Operations/CreateOperation.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion src/app/Http/Controllers/Operations/UpdateOperation.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
9 changes: 6 additions & 3 deletions src/app/Library/CrudPanel/Traits/Fields.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}

/**
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: 9 additions & 9 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,14 +35,14 @@
// 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 - 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');
// }),
Expand Down
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: 9 additions & 9 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,14 +35,14 @@
// 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 - 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');
// }),
Expand Down