Skip to content

Form Data

tanthammar edited this page Nov 13, 2020 · 7 revisions
public Model $model;
public array $form_data;

Access data

  • The data is always accessible via: data_get($this->form_data, 'foo')
  • or the fields name property, like $this->foo, depending on how you setup your form
  • In Lifecycle Hooks you access custom field data via data_get($this->form_data, 'foo')

Model

The model you pass in the mount_form($model) method is accessed as $this->model

Example

    public function onCreateModel()
    {
        data_set($this->form_data, 'password', Hash::make(data_get($this->form_data, 'password')));
        //or 
        $this->form_data['password'] = Hash::make($this->form_data['password']);

        $this->model = User::create($validated_data);
    }

FileUpload fields

This data is never available in the form_data property, you access it with $this->foo because Livewire v2 requires you to define the property on the component.

Clone this wiki locally