The error message suggests that the "state_id" field is not being included in the SQL insert statement. This could be due to a few reasons:
-
The "state_id" field is not marked as fillable in the Employee model. Make sure that the "state_id" field is included in the $fillable array in the Employee model.
-
The "state_id" field is not being set in the form submission. Check that the "state_id" field is being set in the form submission and that it is not being overwritten by any default values.
-
There may be a database constraint that is preventing the "state_id" field from being set. Check that there are no database constraints that are preventing the "state_id" field from being set.
Here's an example of how to include the "state_id" field in the form:
public static function form(Form $form): Form
{
return $form
->schema([
Card::make()
->schema([
Select::make('country_id')->relationship('country', 'name')->required(),
Select::make('state_id')->relationship('state', 'name')->required(),
Select::make('city_id')->relationship('city', 'name')->required(),
Select::make('department_id')->relationship('department', 'name')->required(),
TextInput::make('first_name')->required(),
TextInput::make('last_name')->required(),
TextInput::make('address')->required(),
TextInput::make('zip_code')->required(),
DatePicker::make('birth_date')->required(),
DatePicker::make('date_hired')->required(),
Hidden::make('state_id')->value(request()->input('state_id')),
Hidden::make('city_id')->value(request()->input('city_id')),
]),
]);
}
This includes two hidden fields for "state_id" and "city_id" that are populated with the values from the form submission.