How to remove null values from laravel collection. what is use of filter method on collection. Collection null or empty values remove in laravel 8, laravel 9, laravel 10.
Remove collection null values
laravel use filter() function to remove null values from collection. this method also removed all false equivalent values like empty array, blank string and false. see below example.
Read Also : Laravel custom helper facade
$collection = collect([1, 2, 'anmol', null, false, '', 0, []]); $collection->filter()->all(); // [1, 2, 'anmol']