Skip to content

Commit

Permalink
Merge pull request #3988 from Laravel-Backpack/make-requests-modifiab…
Browse files Browse the repository at this point in the history
…le-v2

Make requests modifiable v2
  • Loading branch information
tabacitu authored Dec 6, 2021
2 parents 05e7167 + f683950 commit db8e28e
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
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

0 comments on commit db8e28e

Please sign in to comment.