TALL-forms
  • TALL-forms
  • Installation
    • Quickstart: Artisan cmd
    • Manual installation
      • Package
      • Translations
      • Css & Theme
      • Javascript
      • Tailwind
      • Laravel Mix
      • Wrapper view
      • Laravel Jetstream/Breeze
  • Upgrade v7 to v8
    • Configuration changes
    • Component & Field changes
    • Blade view changes
    • Notification changes
    • Styling changes
  • Concept
    • Configuration
    • Validation
    • Styling
    • Icons
    • Javascript
    • Layout vs Wrapper
    • Model binding
    • Manually saving data
    • Extend Blade Components
  • Create Forms
    • Form Data
    • Form Types
      • Standard form
      • As modal
      • Without buttons
      • Fields only
      • Headless
    • Form attributes
    • Form buttons
    • Form slots
    • Form methods
    • Lifecycle hooks
    • Render a form
    • Mass generate
  • Fields
    • Declaration
    • Labels
    • Field Slots
    • Field methods
    • Custom field attributes
    • Conditional field
    • Custom view
    • Custom field
    • Custom Livewire component
    • Relations
    • Fields
      • Checkbox
      • Checkboxes
      • FileUpload
      • Honeypot
      • ImageCropper
      • Input
      • Password
      • InputArray
      • KeyVal (array)
      • Radio
      • Range
      • Repeater (array)
      • Search
      • Select & Multiselect
      • Tags
      • TagsSearch
      • Textarea
      • Trix
      • SpatieTags
    • Sponsor Fields
      • More Inputs
      • CKEditor
      • DatePicker
      • Heading
      • Markdown
      • Panels
      • SearchList
      • SelectOptGroup
      • Tabs
      • Trix, file-uploads
  • Blade components
    • Notifications
    • Label wrapper
    • Button
    • Modal blade component
    • Modal form blade component
  • Examples
    • Input examples
    • Array fields example
Powered by GitBook
On this page
  • FieldFoo::make('Foo')->custom()
  • FieldFoo::make('Foo')->relation()
  • saveFoo() - save the data

Was this helpful?

  1. Concept

Manually saving data

FieldFoo::make('Foo')->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'),

FieldFoo::make('Foo')->relation()

The relation() method does the same as custom(), it is just there for code readability

    Select::make('Parent', 'parent_id')
      ->relation()
      ->rule('required'),

saveFoo() - save the data

If you used the custom() or relation() method on your field, it will be excluded from the default save method, so you must save them yourself via the saveFoo() hook.

The method is executed AFTER field validation and AFTER the model is created or updated, meaning that you have access to $this->model even if it is a create form.

protected function saveFoo($validated_field_value)
{
    //the validate field value is passed to the hook
    $field_value = $validated_field_value;
    
    //or get the field value via the fields name property
    $field_value = $this->foo;
    
    //or via form_data
    $field_value = data_get($form_data, 'foo');
    
    //save the data
    $this->model->foo = $field_value;
}

You do NOT have to prefix with FormData

  • Example method name for an array field form_data.people.name will become savePeopleName($validated_value)

  • Example method name for form_data.some_field_name will become saveSomeFieldName($validated_value)

Example; form_data.price

public function savePrice($validated_value)
{
    $this->model->price = $validated_value;
    $this->model->save();
}
PreviousModel bindingNextExtend Blade Components

Last updated 3 years ago

Was this helpful?