Error while doing INSERT - Laravel 5.1 + PostgreSQL

1

I have date fields on my form, but these fields are optional. When I fill in a date the registration is successful, but if I leave the empty date field I get the following error:

SQLSTATE[22007]: Invalid datetime format: 7 ERROR: invalid input syntax for type date: "" (SQL: insert into...

The same happens when I leave a blank field of type (residence number for example), it seems that the postgre does not accept that it is left blank, I know the ...

By the way, the fields were created as null:

$table->date('nascimento')->nullable();

I'm using laravel 5.1 with postgresql. Someone gives me a light?

    
asked by anonymous 18.12.2015 / 20:23

1 answer

1

Resolved:

In the variable that receives the value of the number ( integer ) I did the following:

($request->get('numero') == '') ? NULL : $request->get('numero')

In the variable that receives the value of the birth date ( date ) I did the following:

($request->get('nascimento') == '') ? NULL : $request->get('nascimento')
    
18.12.2015 / 20:44