Refactoring to collection filter Collections are very powerful, this refactor shows the filter method https://laravel.com/docs/8.x/collections#method-filter
requires: laravel 5.1

The filter method filters the collection using the given callback, keeping only those items that pass a given truth test:

Original code



        $arr = array(
            
1299201,
        );

        
$between1and100 array_filter($arr, function ($value) {
            return (
$value >= && $value <= 100);
        });

        

Refactored code



        $arr = array(
            
1299201,
        );

        
$between1and100 collect($arr)->filter(fn($value) => ($value >= && $value <= 100));

        

Here is the output of the code

This is the output of original

[1,2,99]

This is the output of refactor

[1,2,99]

Want to learn more from LLoadout ?

LLoadout is your loadout for Laravel, helping you kickstart your development process. Besides this refactoring site we also make some cool packages and video tutorials !

Go to LLoadout on github