Error doing INSERT - Laravel 5.1 + Postgresql

Asked

Viewed 316 times

1

I have date fields in my form, but these fields are optional. When I fill in a date the registration is successfully performed, but if I leave the date field empty 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 field of the whole type blank (residence number for example), it seems that the postgre does not accept that it is left blank, sei la...

By the way, the fields were created as null:

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

I’m using Portable 5.1 with postgresql. Someone give me a light?

  • 1

    For pass int fields 0 as standard value, and null or current date for date type fields.

  • blz, I’m gonna test here @rray

  • Ball show, it worked! Thanks @rray

  • 1

    Postgres is a little boring in some things but it has cool features as well. Create an answer to help others solve this problem :)

1 answer

1


Solved:

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 receiving the date of birth value(date) I did the following:

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

Browser other questions tagged

You are not signed in. Login or sign up in order to post.