> For the complete documentation index, see [llms.txt](https://lakm.gitbook.io/commenter/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://lakm.gitbook.io/commenter/configuration/sorting.md).

# Sorting

### Sorting Comments

Available Options: All the options in [`LakM\Commenter\Enums\Sort`](https://github.com/Lakshan-Madushanka/laravel-comments/blob/main/src/Enums/Sort.php) class.

* `Sort::TOP` - Sort by custom algorithm (default).
* `Sort::LATEST` - Sort by latest comments.
* `Sort::OLDEST` - Sort by oldest comments.
* `Sort::REPLIES` - Sort by replies count

#### Overwrite default sort order

#### **Globally**

Change the `default_sort` option in `commenter.config` file.

```
// commenter.config

use LakM\Commenter\Enums\Sort;

return [
    // Default comments sort order, See Sort::class for available values
    'default_sort' => Sort::TOP,
];
```

#### **Model-wise (Higher priority)**

Define variable `$commmentsSortOrder` and set the value in [`commentable`](/commenter/basics/usage.md#commentable-model) model.

```
use Illuminate\Database\Eloquent\Model;
use LakM\Commenter\Concerns\Commentable;
use LakM\Commenter\Contracts\CommentableContract;
use LakM\Commenter\Enums\Sort;

class Post extends Model implements CommentableContract
{
    use Commentable;

    $commmentsSortOrder = Sort::TOP;
}
```

### Sorting Replies

Available Options: Following options in [`LakM\Commenter\Enums\Sort`](https://github.com/Lakshan-Madushanka/laravel-comments/blob/main/src/Enums/Sort.php) class.

* `Sort::LATEST` - Sort by latest comments.
* `Sort::OLDEST` - Sort by oldest comments.

#### Overwrite default sort order

#### Globally

Change the `reply.default_sort` option in `comments.config` file.

```
// commenter.config

use LakM\Commenter\Enums\Sort;

return [
    'reply' => [
        // Default comments sort order, available values: Sort::LATEST, Sort::OLDEST
        'default_sort' => Sort::LATEST,
    ],
];
```

#### **Model-wise (Higher priority)**

Define variable `$repliesSortOrder` and set the value in [`commentable`](/commenter/basics/usage.md#commentable-model) model.

```
use Illuminate\Database\Eloquent\Model;
use LakM\Commenter\Concerns\Commentable;
use LakM\Commenter\Contracts\CommentableContract;
use LakM\Commenter\Enums\Sort;

class Post extends Model implements CommentableContract
{
    use Commentable;

    $repliesSortOrder = Sort::TOP;
}
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://lakm.gitbook.io/commenter/configuration/sorting.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
