# Дополнительный настройки

#### Сортировка по умолчанию

По умолчанию ресурсы сортируются по id.

Для изменения установить свойства $sortBy и $sortDirection в компоненте.

{% code title="app/Http/Livewire/Admin/News/NewsList.php" %}

```php
<?php

namespace App\Http\Livewire\Admin\News;

use WebVovan\RockCms\Http\Livewire\ResourceListComponent;

class NewsList extends ResourceListComponent
{
    // Поле для сортировки
    public string $sortBy = 'title';
    
    // Направление сортировки
    public string $sortDirection = 'acs';
    
    ...
}
```

{% endcode %}

#### Количество ресурсов на странице

По умолчанию выводится 10 ресурсов на странице.

Для изменения установите свойство $perPage.

{% code title="app/Http/Livewire/Admin/News/NewsList.php" %}

```php
<?php

namespace App\Http\Livewire\Admin\News;

use WebVovan\RockCms\Http\Livewire\ResourceListComponent;

class NewsList extends ResourceListComponent
{
    // Количество ресурсов на странице [5, 10, 15]
    public int $perPage = 10;
    
    ...
}
```

{% endcode %}

#### Пользовательские обработчики сортировки

Для настройки собственных обработчиков для сортировки полей используйте метод setSortHandlers().

Это может быть полезно если, к примеру, сайт мультиязычный и все переводы модели хранятся в отдельной таблице (как это реализовано в пакете [astrotomic/laravel-translatable](https://github.com/Astrotomic/laravel-translatable)). В таком случае не получится просто отсортировать ресурсы по полю title и нужно будет использовать метод сортировки от создателей пакета.

{% code title="app/Http/Livewire/Admin/News/NewsList.php" %}

```php
<?php

namespace App\Http\Livewire\Admin\News;

use WebVovan\RockCms\Http\Livewire\ResourceListComponent;

class NewsList extends ResourceListComponent
{
    ...
    
    /**
     * Установка обработчиков для сортировки
     *
     * @return array
     */
    public function setSortHandlers(): array
    {
        return [
            'title' => fn($builder, string $sortBy, string $sortDirection) => $builder->orderByTranslation($sortBy, $sortDirection),
        ];
    }

    ...
}
```

{% endcode %}

#### Пользовательские обработчики поиска

Если в свойстве $search указаны поля, которые загружаются через отношения, то для поиска по ним нужно добавить собственные функции в методе setSearchHandlers().

Ниже пример поиска по полю с мультиязычным заголовком (используется пакет [astrotomic/laravel-translatable](https://github.com/Astrotomic/laravel-translatable)).

{% code title="app/Http/Livewire/Admin/News/NewsList.php" %}

```php
<?php

namespace App\Http\Livewire\Admin\News;

use WebVovan\RockCms\Http\Livewire\ResourceListComponent;

class NewsList extends ResourceListComponent
{
    ...

    /**
     * Установка обработчиков для поиска
     *
     * @return array
     */
    public function setSearchHandlers(): array
    {
        return [
            'title' => fn($builder, string $field, string $searchWord) => $builder->whereTranslationLike($field, '%' . $searchWord . '%'),
        ];
    }
}
```

{% endcode %}


---

# Agent Instructions: 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://web-vovan.gitbook.io/rock-cms/ispolzovanie/vyvod-spiska-resursov/dopolnitelnyi-nastroiki.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.
