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.
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.
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.
Reset and re-run all migrations
Drop all tables and re-run all migrations