3

How can I make a repeater field jsonable because I am creating this repeater field into a different plugin and I have created my own plugin. for example: I want to add a repeater field in rainlab.user plugin model but I want to do this by my own plugin so updates on rainlab.user plugin won't affect my work. Thanks

Zakir hussain
  • 621
  • 3
  • 12

1 Answers1

5

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

    });

}
Raja Khoury
  • 3,015
  • 1
  • 20
  • 19