laravel collection check if value exists code example
Example 1: laravel check if item is in collection
$collection = collect([
['product' => 'Desk', 'price' => 200],
['product' => 'Chair', 'price' => 100],
]);
$collection->contains('product', 'Bookcase');
Example 2: laravel check if item is in collection
$collection = collect(['name' => 'Desk', 'price' => 100]);
$collection->contains('Desk');
$collection->contains('New York');
Example 3: laravel check if collection has value
Auth::user()->ports->contains('port', $request->port);