Octobercms: How can I make a repeater field jsonable because I am creating this repeater field into a different plugin

早过忘川 提交于 2019-12-06 09:30:49

You should read about Extending Plugins.

1) First register the events in your custom plugin.php - Example

2) Add the related fields to your migration file - Example - Make sure the field type is set to json or text : $table->json('field_name')->nullable();

Let's say you want to add a Dogs repeater field to the User Model ;

public function boot()
{

    UserModel::extend(function($model)
    {
        $model->addJsonable([
            'dogs',
        ]);
    });

    UsersController::extendFormFields(function($form, $model, $context){

        if (!$model instanceof UserModel) {
            return;
        }

        $form->addTabFields([
            'dogs' => [
                'label'      => 'My Dogs',
                'type'       => 'repeater',
                'form'       => [
                    'fields' => [
                        'breed' => [
                            'label' => 'Breed',
                            'type' => 'dropdown',
                            'options' => [
                                'labrador' => "Labrador",
                                'cocker'   => "Cocker Spaniel"
                            ]
                        ],
                        'name' => [
                            'label' => 'Name',
                            'type' => 'text',
                        ]
                    ],
                ],
            ],
        ]);

    });

}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!