2017-04-14 132 views
0

我试图延长octobercms后端用户字段,但增加了新的后场不创建数据库列,如果我尝试保存表单有一个错误说,这个领域不存在数据库。那么如何为我的新领域添加一个列? 这里是我的代码:扩展字段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' 
      ] 
     ]); 


    }); 
} 

回答

2

扩展一个模型,你不会自动创建在数据库中的字段。

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

Builder Plugin提供图形化创造,应用和回滚迁移的一个非常好的方式。

+2

@Ahmed埃萨姆:我必须指出的是,直接添加到迁移别人的插件,你别管是自找麻烦。有关如何处理此问题的教程,请参阅https://vimeo.com/108040919。 – LukeTowers