BaseModel::save

Usage

void BaseModel::save([ array $values = '[]' ])

Description

Save and update an individual model instance.

Parameters

Parameter Required Type Description
$values No array Optional associative array of values to update the record with. If not provided, the current values of the properties will be used.

Examples

Update Product

use App\Demo\Models\Product;

// Get product id# 61
$id = 61;
if (!$product = Product::whereId($id)) {
    die("No product exists with id# $id");
}

// Update name and price
$product->save([
    'price' => 49.95,
    'name' => 'Exclusive Product'
]);

Update via Properties

use App\Demo\Models\Category;

// Get category
$slug = 'games';
if (!$cat = Category::whereFirst('slug = %s', $slug)) {
    die("No category exists with slug, $slug");
}

// Update name
$cat->name = 'Video Games';
$cat->save();

See Also