【问题标题】:Extending fields doesn't create database columns in OctoberCMS扩展字段不会在 OctoberCMS 中创建数据库列
【发布时间】:2017-09-10 19:32:27
【问题描述】:

我正在尝试在 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'
            ]
        ]);


    });
}

【问题讨论】:

    标签: laravel-5 octobercms octobercms-plugins


    【解决方案1】:

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

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

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

    【讨论】:

    • @Ahmed Essam:我必须指出,将迁移直接添加到您无法控制的其他人的插件中只是自找麻烦。有关如何处理此问题的教程,请参阅 vimeo.com/108040919
    猜你喜欢
    • 2017-01-20
    • 2020-06-25
    • 2016-04-13
    • 2012-10-15
    • 2018-07-05
    • 2019-11-27
    • 1970-01-01
    • 2021-09-02
    • 2014-10-19
    相关资源
    最近更新 更多