Laravel should do this automatically for you. It seems that your frontend is not sending those values as actual null values to the backend. Can you maybe show how you send it to the backend?
Handling FormData null string
Since FormData only can contain strings or blobs, I was wondering how I would prevent the Laravel backend to store the data as the string "null" when using axios in my Vue project.
In my case, I use FormData to send an image along with some other data. Some of the table columns are nullable strings. When I try to save an empty field it get saved as "null" instead of NULL.
Should this be done in the frontend or backend? And how would it be done? Currently, I am doing a check in my frontend.
if (value != null) formData.append(key, value);
Note: The following middleware did not work for me on the backend side: \Illuminate\Foundation\Http\Middleware\ConvertEmptyStringsToNull::class
This is something your frontend should fix in my opinion! Your backend has an API that either receives a string or NULL. If it sends "null" it should handle it as a string, since it's a string ;)
You can create a middleware for this, but that means your users can't use the string "null" anymore as input value. That decision is up to you ;)
Please or to participate in this conversation.