Answers for "laravel collection has value"

PHP
1

laravel check if item is in collection

// You may also pass a key / value pair to the contains method,
// which will determine if the given pair exists in the collection:

$collection = collect([
    ['product' => 'Desk', 'price' => 200],
    ['product' => 'Chair', 'price' => 100],
]);

$collection->contains('product', 'Bookcase');
// false
Posted by: Guest on January-14-2021
4

collection laravel filter

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

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

$filtered->all();

// [3, 4]
Posted by: Guest on November-17-2020
0

laravel reduce

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

$total = $collection->reduce(function ($carry, $item) {
    return $carry + $item;
});

// 6

$total = $collection->reduce(function ($carry, $item) {
    return $carry + $item;
}, 4);

// 10   | where 4 is a initial value
Posted by: Guest on December-14-2020
0

laravel check if collection has value

Auth::user()->ports->contains('port', $request->port);
Posted by: Guest on October-14-2020
0

laravel collection has

$collection = collect(['account_id' => 1, 'product' => 'Desk']);

$collection->has('product');

// true
Posted by: Guest on July-24-2021

Code answers related to "laravel collection has value"

Browse Popular Code Answers by Language