BaseModel::whereId
Usage
?static BaseModel::whereId(string | int $id)Description
Select a single model instance based on the value of the primary key / id column.Parameters
Parameter | Required | Type | Description |
---|---|---|---|
$id | Yes | string | int | The value of the id / primary key column to retrieve record of. |
Return Value
An instance of the model class of the record found. Returns null if no record is found.Examples
Get Product ID# 68
use app\Demo\Models\Product;
// Get product
$id = 68;
if (!$product = Product::whereId($id)) {
die("No product exists with id# $id");
}
print_r($product->toArray());