Link to home
Start Free TrialLog in
Avatar of HelpDeskGeiger
HelpDeskGeigerFlag for United States of America

asked on

Laravel 4 - Eloquent replace null values.

I have a laravel web application that is nearly completed. I have had to switch database servers and have run into an unexpected problem. The new database does not allow null values. Other applications read and write to this database which is why nulls are not allowed. Therefore I will not be able to change the database. What would be the easiest way to check for null values before a save?
Avatar of Ray Paseur
Ray Paseur
Flag of United States of America image

I think you might want to set up a test of this.  When tables are created by CREATE TABLE the column definitions can be set to NOT NULL and can be set to contain a DEFAULT value.  When your script INSERTs data into a row, any columns that are not included are given their default value.  If you INSERT an empty string into a NOT NULL column, the data base will keep it and will return an empty string to the SELECT queries.

So you may be OK right now, assuming that the database tables are defined correctly.
ASKER CERTIFIED SOLUTION
Avatar of HelpDeskGeiger
HelpDeskGeiger
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of HelpDeskGeiger

ASKER

found the answer in the laravel docs that did not force me to change the database.