public static findFirst ([array $parameters])
Allows to query the first record that match the specified conditions
// What's the first robot in the robots table?
$robot = Robots::findFirst();
echo 'The robot name is ', $robot->name, "\n";
// What's the first mechanical robot in robots table?
$robot = Robots::findFirst([
['type' => 'mechanical']
]);
echo 'The first mechanical robot name is ', $robot->name, "\n";
// Get first virtual robot ordered by name
$robot = Robots::findFirst([
['type' => 'mechanical'],
'order' => ['name' => 1]
]);
echo 'The first virtual robot name is ', $robot->name, "\n";
// Get first robot by id (_id)
$robot = Robots::findFirst([
['_id' => new \MongoId('45cbc4a0e4123f6920000002')]
]);
echo 'The robot id is ', $robot->_id, "\n";
Please login to continue.