# Просмотр ресурса

Для вывода кнопки просмотра ресурса в списке нужно переопределить свойство $activeShowButton в компоненте вывода списка ресурсов.

{% code title="app/Http/Livewire/Admin/Posts/PostList.php" %}

```php
<?php

namespace App\Http\Livewire\Admin\Posts;

use App\Models\Post;
use WebVovan\RockCms\Http\Livewire\ResourceListComponent;
use WebVovan\RockCms\View\Components\ActionColumn;
use WebVovan\RockCms\View\Components\Column;
use WebVovan\RockCms\View\Components\EditLinkColumn;

class PostList extends ResourceListComponent
{
    public string $resourceClass = Post::class;

    public string $nameRouteResourceCreate = 'posts.create';
    public string $nameRouteResourceEdit = 'posts.edit';
    public string $nameRouteResourceShow = 'posts.show';

    // Активация кнопки просмотра ресурса
    public bool $activeShowButton = true;

    public array $search = ['title'];

    /**
     * Колонки
     *
     * @return array
     */
    public function columns(): array
    {
        return [
            Column::make('id', 'ID')
                ->sortable(),
            EditLinkColumn::make('title', 'Заголовок')
                ->sortable(),
            Column::make('created_at', 'Дата'),
            ActionColumn::make('Действия')
                ->addClass('text-center'),
        ];
    }
}

```

{% endcode %}

В blade шаблоне в компонент нужно передать модель для редактирования.

{% code title="resources/views/admin/posts/show\.blade.php" %}

```php
...

@section('content')
    <livewire:admin.posts.post-item :resource="$model"/>
@stop
```

{% endcode %}

{% hint style="info" %}
Переменная $model передается из роута. Подробнее про настройку роутов [здесь](/rock-cms/nastroika/routy.md).
{% endhint %}

Создание livewire компонента:

```
php artisan make:livewire Admin/Posts/PostShow
```

Для правильной работы нужно отнаследоваться от ResourceComponent.

{% code title="app/Http/Livewire/Admin/Posts/PostShow\.php" %}

```php
<?php

namespace App\Http\Livewire\Admin\Posts;

use App\Models\Post;
use WebVovan\RockCms\Http\Livewire\ResourceComponent;

class PostShow extends ResourceComponent
{
    public Post $resource;

    public string $resourceClass = Post::class;
    public string $nameRouteResourceList = 'posts.list';
    public string $nameRouteResourceEdit = 'posts.edit';

    protected $rules = [
        'resource.title' => 'string|required',
        'resource.desc' => 'string',
    ];

    public function init()
    {
    }

    public function save()
    {
    }

    public function render()
    {
        return view('livewire.admin.posts.post-show');
    }
}

```

{% endcode %}

В шаблоне компонента просто перечисляем список полей с атрибутом readonly.

{% hint style="info" %}
Rock.Cms поставляется с большим количеством уже готовых [полей](/rock-cms/ispolzovanie/sozdanie-i-redaktirovanie-resursa/polya.md). У большинства есть атрибут readonly, который выводит содержимое только для чтения.
{% endhint %}

{% code title="resources/views/livewire/admin/posts/post-show\.blade.php" %}

```php
<div>
    <x-rock-cms::fields.input readonly field="resource.title" title="Заголовок"/>
    <x-rock-cms::fields.editor
        :model="$resource->desc"
        field="resource.desc"
        enableMedia
        readonly
        title="Описание"/>
</div>
```

{% endcode %}

В итоге получаем такую страницу.

![](/files/FojUkYOIYTXkJUxDlaAj)


---

# 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/prosmotr-resursa.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.
