Support the ongoing development of Laravel.io →
Database Eloquent

I am trying to call Eloquent's save() method on an existing record but getting an error from Illuminate's Query Builder.

Following the documentation on [Laravel's web site] (http://laravel.com/docs/eloquent#insert-update-delete) for updating a retrieved model, and also looking at the example here: http://stackoverflow.com/questions/19684925/laravel-eloquent-orm-save-update-vs-create, my code appears to follow the expected convention, but instead I get the error mentioned in the title of this post. Also, I have a thread on Stackoverflow for this http://stackoverflow.com/questions/24023516/call-to-undefined-method-illuminate-database-query-buildersave/24024679#24024679

My code:

$this->employee        = Employee::where('login', $login)->get();
$this->employee->first_name        = 'John';
$this->employee->last_name        = 'Doe';
$this->employee->save();

If I use Employee::find(1); it works fine, but I don't know what the id of the user is so I can't use the find method. Seems like a bug to me. I've tried using only Employee::where('login', $login); without the ->get() method, but that doesn't work either.

What does work besides the find(1) method?

The error is truncated in the subject title, so here is the full error msg:

Symfony \ Component \ Debug \ Exception \ FatalErrorException Call to undefined method Illuminate\Database\Eloquent\Collection::save()
Last updated 2 years ago.
0

Get() returns a collection. Try first() instead.

Last updated 2 years ago.
0

That worked, thanks.

It would be nice to know which methods can and can't be used. The docs aren't very clear on that.

Last updated 2 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2025 Laravel.io - All rights reserved.