Check your /app/Http/Kernel.php file and see if this middleware is enabled: \Illuminate\Foundation\Http\Middleware\ConvertEmptyStringsToNull::class,
Best Way to Convert Empty String from Input to Null for DB
I've got a user reg. form with a ton of fields and most of them are nullable (alt. email, alt. phone, etc....). I notice that empty inputs translate to empty strings which is not technically null obviously and so I get:
Integrity constraint violation: column cannot be null
This seems stupid to me. Should I check and convert the values to null if they are empty or is there some option in validation that allows for empty strings? What's the best way to handle it if I should convert them to null?
Laravel already has a built-in middleware for converting empty strings to null (the one that @Cronix already pointed out). Your error message (column cannot be null) suggest that the specific column is NOT nullable.
Please or to participate in this conversation.