Builder::first()
Limit the results from a query to a single result and return the first instance if available otherwise null.
Return
(TECEventsCustom_TablesV1ModelsModel|array|null) The requested model in the required format, or null if the model could not be found.
Source
File: src/Events/Custom_Tables/V1/Models/Builder.php
public function first() {
$results = $this->limit( 1 )->get();
if ( empty( $results ) ) {
return null;
}
$result = reset( $results );
switch ( $this->output_format ) {
case OBJECT:
default:
return $result instanceof $this->model ? $result : null;
case ARRAY_N:
return is_array( $result ) ? array_values( $result ) : null;
case ARRAY_A:
return is_array( $result ) ? $result : null;
}
}
Changelog
| Version | Description |
|---|---|
| 6.0.0 | Introduced. |