Illuminate\Database\Eloquent\Model::fresh PHP Method

fresh() public method

Reload a fresh model instance from the database.
public fresh ( array | string $with = [] ) : static | null
$with array | string
return static | null
    public function fresh($with = [])
    {
        if (!$this->exists) {
            return;
        }
        if (is_string($with)) {
            $with = func_get_args();
        }
        $key = $this->getKeyName();
        return static::newQueryWithoutScopes()->with($with)->where($key, $this->getKey())->first();
    }

Usage Example

Exemplo n.º 1
0
 /**
  * If object was saved
  *
  * @param  string $message
  */
 public function updated($message)
 {
     $model = $this->model->fresh();
     if ($model->updated_at->diffInSeconds() < 5) {
         return $this->flash->success($message);
     }
     $this->error(trans('alert::errors.updating'));
 }
Model