When a field is empty or even with spaces, a mysql error is thrown, specifying that the field does not have a default value. If there is a character other than empty or spaces it works.
This seems like a call to empty() somewhere and causing the issue? ..the value should be empty string in the query string, but appears as null or undefined.
When saving the edit form, a field with some characters that is empty will not cause an error, but will not save. However the other fields changes do save at the same time, as long as its not empty. No error is thrown during that operation...
For me it's a bug, unless i'm missing an important configuration detail ?
..and I don't want to "allow null" on my fields
I had problem with empty fields in my migrations. From this thread
https://laravel.io/forum/08-08-2015-eloquent-create-says-column-has-no-default-value
I've found that since Laravel 5.1, mysql connection is set to run in strict mode
In config/database.php I've changed strict to false for the mysql connection and it did work for my inserts.
However I still have a query exception when one field is left empty:
QueryException In Connection.php line 647 :
SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'description' cannot be null
Ok, I've found the solution. There is not bug, it's a feature of Laravel, possibly to match with the default strict mode...
In this thread
https://laracasts.com/discuss/channels/laravel/laravel-54-auto-convert-empty-text-input-to-null
They suggest commenting the middleware \Illuminate\Foundation\Http\Middleware\ConvertEmptyStringsToNull::class in app\Http\Kernel.php.
..it does work now as expected (in combination with the mysql strict mode false)
For reference, to use strict mode and NULL values when input are empty, the fields allowed to be "empty" would need the "allow null" flag in the database.
Most helpful comment
Ok, I've found the solution. There is not bug, it's a feature of Laravel, possibly to match with the default strict mode...
In this thread
https://laracasts.com/discuss/channels/laravel/laravel-54-auto-convert-empty-text-input-to-null
They suggest commenting the middleware
\Illuminate\Foundation\Http\Middleware\ConvertEmptyStringsToNull::classinapp\Http\Kernel.php...it does work now as expected (in combination with the mysql strict mode false)