gpt4 book ai didi

laravel-backpack - 添加字段以创建请求 [Backpack for Laravel v4]

转载 作者:行者123 更新时间:2023-12-04 15:39:43 25 4
gpt4 key购买 nike

我需要在推送到 Backpack 的 store 方法中的请求中设置一个 key=>value;

在 v3 中,我有一个像这样工作的 store 方法;

public function store(StoreRequest $request) {

$request->request->set('account_type', User::ACCOUNT_TYPE_BASIC);
$redirect_location = parent::storeCrud($request);
return $redirect_location;

}

但是在尝试为仍在开发的项目中保持最新状态时,我正在更新到 v4 并在尝试使用文档中推荐的 traitStore 或 traitUpdate 方法时遇到向 $request 对象添加/删除任何内容的问题.

这不起作用;
public function store(StoreRequest $request) {

$request->request->set('account_type', User::ACCOUNT_TYPE_BASIC);
$redirect_location = $this->traitStore();
return $redirect_location;

}

具体来说,'account_type' 键不包含在通过 traitStore 发送到数据库的请求中,它只使用(在这种情况下)setupCreateOperation() 方法中为此 Crud 定义的字段。

有什么我在这里遗漏的,还是我需要完全管理我需要操纵请求而不是利用各种背包 crud 方法的任何东西的保存/更新?

最佳答案

问题很可能是在 v4 中。 getStrippedSaveRequest at the bttom of this class 故意删除该属性,因为它不是 CRUD 面板中的注册字段

  /**
* 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.
*/
public function getStrippedSaveRequest()
{
return $this->request->only($this->getAllFieldNames());
}

您可以通过将 this 属性添加为 CRUD 面板中的隐藏字段来解决此问题,如下所示:
$this->crud->addField([
'name' => 'account_type',
'type' => 'hidden'
]);

现在该字段不会出现在页面上,但它会被注册并且在创建过程之前不再被删除。

关于laravel-backpack - 添加字段以创建请求 [Backpack for Laravel v4],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58226153/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com