user1876234 user1876234 - 7 months ago 38
SQL Question

Laravel 1048 Column cannot be NULL on storing data

When I'm trying to save a new contact I'm getting

1048 Column 'username' cannot be NULL
error. It's pretty obvious that cause of this error is empty value of
, however I'd like to make it work without setting a column to NULL or checking if
POST data is empty and then setting it's value to

I've seen numerous of examples, where column is not set to NULL and/or data is not set to
before saving to database.

Or maybe I'm wrong and I missed something ?

I hope someone could comment on that..

$contact = new Contact;
$contact->name = Input::get('name');
$contact->username = Input::get('username');


Set default non-null values for the Input variable(s).

$contact = new Contact;
$contact->name      = Input::get('name');
$contact->username  = Input::get('username', false);