Laravel-admin: $form->saving() 的回调函数中使用 $form->ignore() , 会没有成功忽略相关字段.

Created on 25 Aug 2017  ·  7Comments  ·  Source: z-song/laravel-admin

应该要在 Form 类 中的prepare 方法在中 回调函数之后加入 以下代码
$this->inputs = $this->removeIgnoredFields($this->inputs);
即:

    protected function prepare($data = [])
    {
        $this->inputs = $this->removeIgnoredFields($data);

        if (($response = $this->callSaving()) instanceof Response) {
            return $response;
        }
        $this->inputs = $this->removeIgnoredFields($this->inputs);

        $this->relations = $this->getRelationInputs($this->inputs);

        $this->updates = array_except($this->inputs, array_keys($this->relations));
    }

Most helpful comment

我找到了合适的解决方法:
1 在saving()之外使用ignore
2 在saving()内使用request()->request拿到请求所有request参数

这样子就可以在form表单里边使用数据库未定义的columns了。

All 7 comments

哈哈哈,刚好也遇到这个问题,多谢

这个问题这么久了,还没更新上去?

同样的问题,使用unset也没有作用。

$form->ignore()不是写在$form->saving()的回调函数中的

我找到了合适的解决方法:
1 在saving()之外使用ignore
2 在saving()内使用request()->request拿到请求所有request参数

这样子就可以在form表单里边使用数据库未定义的columns了。

很奇怪,文档里面好像没写ignore是在saving里面用的吧

@z-song大大不用生气,我们是因为ignore在saving外面用时无法在saving取得栏位内容...所以才会试着用在saving里面。非常谢谢@scue提供的两种方法

Was this page helpful?
0 / 5 - 0 ratings

Related issues

abufalbo picture abufalbo  ·  3Comments

amun1303 picture amun1303  ·  3Comments

vlongen picture vlongen  ·  3Comments

chenyongmin picture chenyongmin  ·  3Comments

MarKco picture MarKco  ·  3Comments