2
I have an entire field and a date field that are not mandatory and are programmed to accept NULL, but when I send the form data without filling it in my controller receives the empty value instead of ignoring the field, which generates the error:
Incorrect integer value: '' for column vendedor_id
how can I fix 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',
];
}
Provide your validation? and also where are you doing this code? I believe it all comes down to validation!!!
– novic
You need to post the code snippet to your question to make it clearer. It could be two different problems (or more). We need more details.
– Wallace Maxters
Make a Submit without sending the required values. Debug with function
dd
before the Insert.– Wallace Maxters
Is this form being sent via Ajax? I’ve had problems like this when using
FormData
.– Wallace Maxters
"vendedor_id" => "" "data_sale" => ""
– Raylan Soares
Yes, it’s via Ajax @Wallacemaxters
– Raylan Soares
Raylan anyway this error occurs because you are trying to insert a string into a BD field (column) that is reset to integers (
integer
)– Miguel