0

I'm trying to extend backend user fields in octobercms but after adding a new field if I try to save the form there's an error says that this field doesn't exist in database. So how can add a column for my new field? Here's my code:

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'
            ]
        ]);


    });
}
Ahmed Essam
  • 1,000
  • 2
  • 8
  • 23

1 Answers1

2

Extending a model will not automatically create the fields in the database for you.

To create database fields, you need to create a migration and then run it.

The Builder Plugin offers a very nice way of graphically creating, applying and rolling back migrations.

Joseph
  • 2,737
  • 1
  • 30
  • 56
  • 2
    @Ahmed Essam: I must point out that adding migrations directly to somebody else's plugin that you don't control is just asking for trouble. See https://vimeo.com/108040919 for a tutorial on how to take care of this problem. – LukeTowers Apr 15 '17 at 08:12