Support the ongoing development of Laravel.io →
Database Eloquent
Last updated 2 years ago.
0

Removing the value from the $formData should work. Setting a key null does not delete from the array. Instead, use unset like this:

foreach ($formData as $key => $value)
{
    if ($value == "")
        unset( $formData[$key] );
}

This should work.

Last updated 2 years ago.
0

Please notice here that I'm trying to perform an update of the form (not insert). Unfortunately unsetting an empty field from the array will cause that field to be skipped while updating. So any old value of that field would remain untouched, while I actually want to be able to overwrite old values to NULL.

Last updated 2 years ago.
0

Sorry, I must have missed the update. In that case setting the value to null should work

$formData[$key] = null;

but like you said I doesn't...

Last updated 2 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

Janneman84 janneman84 Joined 27 Nov 2014

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.