The statement of the question is wrong. find
does not return Collection
, returns Model
.
And it's easy to solve the problem if you're using a variable and saving the result of the query on it.
See:
$user = User::find(1);
$user->update(...);
dd($user); // Valor atualizado
With the invention of the tap
function in newer versions of Laravel, you could do this:
return tap(User::find(1))->update([
'name' => $name,
'age' => $age,
]);
Now, if your query is in relation to update
that is returned from Query Builder, you really need to do another query, since the update is not done on top of each collection item, but directly on the database.
Example:
$query = User::where(['x' => 'y']);
$query->update(['z' => 'x']);
$users = $query->get();