💡 Laravel Tip: $model->fresh()
vs $model->refresh()
These two Eloquent methods don’t get much attention — but they can save you from subtle bugs when working with updated models.
Imagine you have a $user
model:
$user = User::find(1);
$user->update(['email' => 'new@email.com']);
Now, if you immediately check $user->email
, you’ll still see the old value!
That’s because update()
writes to the database, but doesn’t refresh your in-memory object.
✅ To fix this:
$user->refresh(); // reloads the same instance from DB
echo $user->email; // now shows the updated email
And if you prefer a new instance instead of modifying the current one:
$freshUser = $user->fresh();
$model->refresh()
→ updates the current object with latest DB data$model->fresh()
→ returns a new instance with latest DB data
Small details like this make your code more predictable and bug-free. 🚀
#Laravel #Eloquent #PHP #WebDevelopment #CleanCode