0

我正在尝试在 octobercms 中扩展后端用户字段,但是在添加新字段后,如果我尝试保存表单,则会出现错误,表明该字段在数据库中不存在。那么如何为我的新字段添加一列?这是我的代码:

public function boot()
{
    // Extend all backend form usage
    Event::listen('backend.form.extendFields', function($widget) {

        // Only for the User controller
        if (!$widget->getController() instanceof \Backend\Controllers\Users) {
            return;
        }

        // Only for the User model
        if (!$widget->model instanceof \Backend\Models\User) {
            return;
        }

        // Add an extra birthday field
        $widget->addTabFields([
            'birthday' => [
                'label'   => 'Birthday',
                'comment' => 'Select the users birthday',
                'type'    => 'datepicker',
                'tab'     => 'Billing'
            ]
        ]);


    });
}
4

1 回答 1

2

扩展模型不会自动为您在数据库中创建字段。

要创建数据库字段,您需要创建一个迁移然后运行它。

Builder Plugin提供了一种非常好的以图形方式创建、应用和回滚迁移的方法。

于 2017-04-14T15:07:54.307 回答