Search code examples
laravel-5save

laravel save() returns error Call to undefined method stdClass::save()


Why does save() returns an error "Call to undefined method stdClass::save()" below :

public function update($category,$route)
{
    $category = DB::table('categories')->where('id', $category)->first();
    $category->field = 'changed';
    $category->save();
    ...

and works fine here :

public function store()
{
    ...
    $category = new Category(request(array_column($table->fields, 'name')));
    $category->save();

What do I miss?


Solution

  • DB query builder, return std class object, so this object dont contain method save . when you get item by using eloquent model , this return object from the model so that method save is eloquent model method.