collection laravel filter

70

collection laravel filter -

$collection = collect([1, 2, 3, 4]);

$filtered = $collection->filter(function ($value, $key) {
    return $value > 2;
});

$filtered->all();

// [3, 4]

filter collection (laravel) -

$itemCollection = collect($contacts);
$filtered = $itemCollection->filter(function($item) use ($search) {
    return stripos($item['username'],$search) !== false;
});

Comments

Submit
0 Comments