diff --git a/src/Illuminate/Database/Eloquent/Builder.php b/src/Illuminate/Database/Eloquent/Builder.php index 18abb917d570..fb518a93db71 100755 --- a/src/Illuminate/Database/Eloquent/Builder.php +++ b/src/Illuminate/Database/Eloquent/Builder.php @@ -282,14 +282,19 @@ public function orWhere($column, $operator = null, $value = null) * Add an "order by" clause for a timestamp to the query. * * @param string|\Illuminate\Database\Query\Expression $column + * @param int $limit * @return $this */ - public function latest($column = null) + public function latest($column = null, $limit = null) { if (is_null($column)) { $column = $this->model->getCreatedAtColumn() ?? 'created_at'; } + if (! is_null($limit)) { + $this->query->limit($limit); + } + $this->query->latest($column); return $this; @@ -299,14 +304,19 @@ public function latest($column = null) * Add an "order by" clause for a timestamp to the query. * * @param string|\Illuminate\Database\Query\Expression $column + * @param int $limit * @return $this */ - public function oldest($column = null) + public function oldest($column = null, $limit = null) { if (is_null($column)) { $column = $this->model->getCreatedAtColumn() ?? 'created_at'; } + if (! is_null($limit)) { + $this->query->limit($limit); + } + $this->query->oldest($column); return $this;