![](/img/trans.png)
[英]How I change the option name on select field of backpack-for-laravel
[英]How can I override the store function in backpack-for-laravel v5?
我已經將我的應用程序從 backpack-for-laravel v4.1 更新到 v5,但現在我在覆蓋商店 function 時遇到了問題。我遵循了升級指南和步驟 15: https://backpackforlaravel.com/docs/ 5.x/升級指南#step-15
但不幸的是,我的首選選項 A 不適合我。 這是我的 function 在 v4.1 中的樣子:
public function store()
{
// do something before validation, before save, before everything
$this->crud->setOperationSetting('saveAllInputsExcept', ['save_action']); //somehow required...
$end = strtotime('+1 hour', strtotime($this->crud->getRequest()->request->get('start'))); //set end automatically after 1h
$this->crud->getRequest()->request->add(['end'=> $end]);
$response = $this->traitStore();
// do something after save
return $response;
}
我現在將其轉換為符合 v5 要求,如下所示:
public function store()
{
$this->crud->set('strippedRequest', function($request) {
$end = '2023-02-01 14:00:00';
$request->add([ 'end' => $end ]);
return $request->except(['_save_action', '_token', '_http_referrer']);
});
return $this->traitStore();
}
我什至嘗試使用 static 值,但我不斷收到 SQL 的錯誤,即字段“end”沒有默認值...意味着沒有將 end 值添加到請求中。
感謝任何形式的支持。 謝謝
謝謝你的問題。 升級指南示例中確實存在問題。
我剛剛向文檔提交了一個 PR 來修復它: https://github.com/Laravel-Backpack/docs/pull/404
應該盡快合並!
您可以在 PR diff 中看到實際工作的解決方案。
干杯
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.