Available for select projects New York · Working worldwide
Rappasoft LLC
Menu
Loading snippet

Library / Snippet

Eloquent’s fresh() and refresh() Are Not the Same

Laravel Eloquent

refresh() reloads the model in-place from the database.

fresh() returns a new instance.

1$user->name = 'John';
2$user->refresh(); // Will discard changes and reload
3 
4$newUser = $user->fresh(); // $user still has changes, $newUser doesn't

Subtle difference, big impact.