Laravel Collection Public API: has

November 29, 2016 —John Koster

has($key)

The has method is used to determine if a item exists in the collection based on a given $key. The has method returns true if the item exists and false if it does not.

The following example demonstrates the usage of the has method:

1<?php
2 
3use Illuminate\Support\Collection;
4 
5// Create a new collection instance.
6$collection = new Collection([
7 'first' => 'I am first',
8 'second' => 'I am second'
9]);
10 
11// true
12$collection->has('first');
13 
14// true
15$collection->has('second');
16 
17// false
18$collection->has('third');

Some absolutely amazing
people

The following amazing people help support this site and my open source projects ♥️
If you're interesting in supporting my work and want to show up on this list, check out my GitHub Sponsors Profile.