I have an integer field and a date field that are not required and are programmed to accept NULL, but when I send the form data without filling in, my controller receives the empty value instead of ignoring the field, which generates the error:
Incorrect integer value: '' for column vendor_id
How can I resolve this?
Migration:
$table->integer('vendedor_id')->unsigned()->nullable();
$table->date('data_venda')->nullable();
Controller:
$new = $this->repository->create($request->all());
View:
<div id="vendedor_id" class="form-group col-sm-4 opt">
<label for="vendedor_id">Vendedor:</label>
<select name="vendedor_id" class="form-control select2">
<option value=""></option>
<option value="1">User 1</option>
<option value="2">User 2</option>
</select>
</div>
<div id="data_venda" class="form-group col-sm-4">
<label for="data_venda">Data:</label>
<input type="date" name="data_venda" class="form-control">
</div>
In my request I have some validations for the required fields, but it does not include anything about these 2 fields. Ex.:
public function rules()
{
return [
'cnpj' => 'numeric|required|cnpj|unique:empresas',
'razao_social' => 'required',
];
}