BaseModel::insert
Usage
static BaseModel::insert(array $values)Description
Insert a new record into the database table assigned to the model class.Parameters
Parameter | Required | Type | Description |
---|---|---|---|
$values | Yes | array | Associative array of the values of the record to insert, the keys being the column names and the values being that of the new record. |
Return Value
An instance of the model class representing the newly created record.Examples
Insert New Category
use App\Demo\Models\Category;
// Insert category
$cat = Category::insert([
'slug' => 'kitchen',
'name' => 'Kitchenware'
]);
print_r($cat->toArray());
Insert Multiple Records
use App\Demo\Models\Category;
// Insert three categories
Category::insert(
['slug' => 'car', 'name' => 'Cars'],
['slug' => 'games', 'name' => 'Video Games'],
['slug' => 'kichen', 'name' => 'Kitchenware']
);