LMongo\Eloquent\Collection::find PHP Method

find() public method

Find a model in the collection by key.
public find ( mixed $key, mixed $default = null ) : Model
$key mixed
$default mixed
return Model
    public function find($key, $default = null)
    {
        return array_first($this->items, function ($key, $model) use($key) {
            return $model->getKey() == $key;
        }, $default);
    }

Usage Example

 public function testFindMethodFindsModelById()
 {
     $mockModel = m::mock('LMongo\\Eloquent\\Model');
     $mockModel->shouldReceive('getKey')->andReturn(1);
     $c = new Collection(array($mockModel));
     $this->assertTrue($mockModel === $c->find(1));
 }