AdRock
5 months ago

Replace collection key value with null

Posted 5 months ago by AdRock

I have a collection retrieved by Eloquent and I want to replace all occurrences of a specific key with a value of null

I have tried using the reject()

$collection = $collection->reject(function ($value, $key) {
     return $key == 'model';
});

and also transform but get the same result

$collection->transform(function($item) {
    $item->mondel = null;
    return $item;
});

For both I don't get null but and empty string

Please sign in or create an account to participate in this conversation.