Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions src/Illuminate/Database/Eloquent/Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down