Skip to content

Remove the field from the form input before saving #212

@mrigankgaur

Description

@mrigankgaur

I want to remove country_id field from the form input before saving every time I am getting unknown column country_id.  

protected function form()
{
    $form = new Form(new City());

    // Country dropdown (virtual field)
    $form->select('country_id', 'Country')
        ->options(Country::all()->pluck('name', 'id'))
        ->load('state_id', '/admin/api/states'); // AJAX-load states

    // Dependent state dropdown
    $form->select('state_id', 'State')->options(function ($id) {
        return $id ? State::where('id', $id)->pluck('name', 'id') : [];
    });

    $form->text('name', 'City Name')->required();

    // Clean up before saving
    $form->saving(function ($form) {
        // Remove virtual field
        $form->deleteInput('country_id');
    });

    return $form;
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions