Вывод списка ресурсов

Для вывода списка ресурсов нужно создать новый livewire компонент без шаблона.

php artisan make:livewire Admin/Posts/PostList --inline

Для вывода списка ресурсов в blade шаблоне в секции content подключим созданный компонент.

// resources/views/admin/posts/list.blade.php

...

@section('content')
    <livewire:admin.posts.post-list />
@stop

Код компонента:

// app/Http/Livewire/Admin/Posts/PostList.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 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'),
        ];
    }
}

Last updated