Open allowing opened 6 years ago
You can just disable the ConvertEmptyStringsToNull
middleware in your App\Http\Kernel
if this is causing you trouble.
@michaeldyrynda Yes, I can. but the reason for this problem is not ConvertEmptyStringsToNull.
In that case, can you clarify what you meant when you said that it doesn't work very well sometimes? Are you getting errors, or some other measure of "not working"?
If you have a default of empty string and haven't marked the column as nullable
, you won't be able to insert a null
value into it. Laravel doesn't know your database schema in code, so you won't get an error like that until you try and insert invalid data to the database.
This sounds like an attempt to chat with support, not an idea for Laravel. Have you considered using the forums at Laracasts or perhaps the Slack to have a real chat instead?
I mean, can have some validators like this: if_null_set:''
, if_null_remove_the_item
, if_empty_string_set:null
I am getting errors:
Database default values are only used if none is provided by the application. You provide a value, null
, which is invalid. Use a mutator to store empty strings in case of nulls.
You could also use TrimStrings
instead of ConvertEmptyStringsToNull
. Validation shouldn’t manipulate the request data as you suggested.
I'm now using this way:
public function setNoteAttribute($value)
{
if (is_null($value)) {
$this->attributes['note'] = '';
}
}
You can filter the array of data like that
$p = new Person(array_filter($data));
ConvertEmptyStringsToNull