In Laravel, when you want to update the model that already exists in the database, you would first retrieve that model, set any attributes you wish to update, and then call the model’s save method like so. use App\Models\Book; $book = Book::find(1); $book->name = 'Maharani'; $book->author = 'Ruskin Bond'; $book->save(); Sometimes, though, it might be the case when you have a model instance, you have set some of the model attributes and for some reason, you want to discard all that has been set on the model and just revert back to the original model instance.

Laravel comes with a refresh() method, which when called on the model instance, will discard all the model attributes update and re-hydrate the existing model using fresh data from the database like so. $book = Book::where('name', 'Maharani')->first(); $book->name = 'Room on the Roof'; $book->refresh(); $book->name; // "Maharani"

But if you want the model intact and create a fresh new model instance instead, you can use the refresh() method like so.
Newsletter

Get the latest Laravel/PHP jobs, events and curated articles straight to your inbox, once a week

Fathom Analytics | Fast, simple and privacy-focused website analytics. Fathom Analytics | Fast, simple and privacy-focused website analytics.
Achieve superior email deliverability with ToastMail! Our AI-driven tool warms up inboxes, monitors reputation, and ensures emails reach their intended destination. Sign up today for a spam-free future. Achieve superior email deliverability with ToastMail! Our AI-driven tool warms up inboxes, monitors reputation, and ensures emails reach their intended destination. Sign up today for a spam-free future.
Community Partners