Laravel 7.x: Difference between fresh and refresh method?

Viewed 10283

While I was reading Laravel documentation, I faced a method named fresh and refresh on the Eloquent model. Please explain the major difference between them? I am having hard time understanding those.

2 Answers

This is the comment for the refresh method on Illuminate\Database\Eloquent\Model :

/**
 * Reload the current model instance with fresh attributes from the database.
 *
 * @return $this
 */
public function refresh()

Here is the one for fresh:

/**
 * Reload a fresh model instance from the database.
 *
 * @param  array|string  $with
 * @return static|null
 */
public function fresh($with = [])

refresh will refresh the current model instance (including relationships). fresh will get a new instance of the model from the database and return it.

enter image description here

RefreshCommand

Reset and re-run all migrations


FreshCommand

Drop all tables and re-run all migrations

Related