Skip to content

Custom Data

tanthammar edited this page Nov 13, 2020 · 3 revisions

->custom()

If you want to be in control of how a field is saved add the custom() method to the field

    Input::make('My custom field', 'foo')
      ->custom()
      ->rule('required'),

saveFoo() - save the data

You must save the data your self, the custom fields are excluded from the default save method. You can omit FormData in the method name, if it is an array like form_data.name.sv the method name becomes saveNameSv()

The data is accessed via data_get($form_data, 'customname') or the fields name property, like $this->fieldname, depending on how you setup your form

The method is executed AFTER the model is saved.

Meaning that you have access to $this->model.

public function saveFoo($validated_value)
    {
        // get the field value via the fields name property
        $field_value = $validated_value;
        //or
        $field_value = $this->foo;
        //save the data
        $this->model->foo = $field_value;
    }

view(string $bladefile)

A nice combination is to use the custom property together with a custom view. This way you can make any field you want.

Input::make('My custom field', 'customname')
      ->custom()
      ->view('path.mybladeview')
      ->rule('required'),
Clone this wiki locally