Skip to content

Conversation

ejgandelaberon
Copy link
Contributor

This PR allows DataTables extending Yajra\DataTables\Services\DataTable to be passed as route action when defining routes:

// web.php
Route::get('/roles', RolesDataTable::class);

// RolesDataTable
class RolesDataTable extends Yajra\DataTables\Services\DataTable
{
    protected ?string $view = 'roles.index';

    public function dataTable(...) {...}

    public function query(...) {...}

    #[\Override]
    protected function viewData(): array
    {
        return [
            'title' => 'Manage Roles',
            'breadcrumbs' => [
                'Administration',
                'ACL',
                'Roles',
            ],
            'widgets' => view('roles.widgets'),
            'rolesCount' => $this->query()->count(),
        ];
    }
}

// roles/index.blade.php
<x-layouts.admin>
    <x-slot:title>{{ $title }}</x-slot>

    <x-breadcrumbs>
        @foreach($breadcrumbs as $breadcrumb)
            <x-breadcrumbs.item>{{ $breadcrumb }}</x-breadcrumbs.item>
        @endforeach
    </x-breadcrumbs>

    {{ $widgets }}

    <x-stat-card :value="$rolesCount" description="Roles Count" />

    <x-datatable-wrapper :data-table="$dataTable" />
</x-layouts.admin>

Copy link

sonarqubecloud bot commented Oct 3, 2025

@yajra yajra changed the title DataTable as route action feat: DataTable as route action Oct 3, 2025
@yajra yajra merged commit efd7e68 into yajra:master Oct 3, 2025
2 of 3 checks passed
@yajra
Copy link
Owner

yajra commented Oct 3, 2025

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants