If you have a model that you want to refresh with data from the database, it seems like you have to find it manually all over again.
// Got a user
$user = User::find(1);
// Refresh the user
$user = User::find($user->getKey());
I'd like to add a helper method like refresh()
or reload()
that will automatically refresh the model with current data from the database.
$user->reload();
Thoughts?
Yeah I do that sometimes, would be nice I agree
Yeah I also need to do that sometimes, would be nice.
I agree, It would be a nice thing to have.
Yep, have had this need as well. Feel free to make it the pull if you want.
What ever happened to this? Where did it go?
egrep -r reload vendor/laravel/framework/src/Illuminate/Database/
fresh()
derp - Thank you!
$user = $user->fresh()
You will need to assign it like this... otherwise it will not change automatically.
Isn't $user->refresh()
something you could use?
I could not find any information about fresh() Eloquent method in Laravel official documentation. Anyone knows why? It's very useful feature. Thanks
@strainovic Here's the link you're looking for.
Most helpful comment
fresh()