Laravel - Collections - Method Get

The get method returns the item at a given key. If the key does not exist, null is returned:

    
    $collection = collect(['name' => 'taylor', 'framework' => 'laravel']);
    
    $value = $collection->get('name');
    
    // taylor
	

You may optionally pass a default value as the second argument:

    
    $collection = collect(['name' => 'taylor', 'framework' => 'laravel']);
    
    $value = $collection->get('age', 34);
    
    // 34
	

You may even pass a callback as the method's default value. The result of the callback will be returned if the specified key does not exist:

    
    $collection->get('email', function () {
        return '[email protected]';
    });
    
    // [email protected]