LMongo\Eloquent\Collection::contains PHP Method

contains() public method

Determine if a key exists in the collection.
public contains ( mixed $key ) : boolean
$key mixed
return boolean
    public function contains($key)
    {
        return !is_null($this->find($key));
    }

Usage Example

 public function testContainsIndicatesIfKeyedModelInArray()
 {
     $mockModel = m::mock('LMongo\\Eloquent\\Model');
     $mockModel->shouldReceive('getKey')->andReturn(1);
     $c = new Collection(array($mockModel));
     $mockModel2 = m::mock('LMongo\\Eloquent\\Model');
     $mockModel2->shouldReceive('getKey')->andReturn(2);
     $c->add($mockModel2);
     $this->assertTrue($c->contains(1));
     $this->assertTrue($c->contains(2));
     $this->assertFalse($c->contains(3));
 }