Framework: [Proposal] Eloquent method for refreshing model with latest data from database

Created on 31 Jul 2014  Â·  11Comments  Â·  Source: laravel/framework

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?

Most helpful comment

fresh()

All 11 comments

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.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

kerbylav picture kerbylav  Â·  3Comments

JamborJan picture JamborJan  Â·  3Comments

YannPl picture YannPl  Â·  3Comments

shopblocks picture shopblocks  Â·  3Comments

ghost picture ghost  Â·  3Comments