Fork me on GitHub

DataTable

You can extend Rapyd "AbstractDataTable" to make custom {Entity}Table to display filter and paginate custom datasets.
You can use Eloquent Models or any other source of data.
AbstractTable has only the logic of pagination, sorting and a default "datatable" view you can extend via blade template.


id title author body
20 Non eius facere minus quasi recusandae quia error. Clay Commodi aspernatur odit et beatae. Ipsum voluptatu...
19 Non eaque et quia assumenda. Clay Molestias neque porro voluptate quia consequatur....
18 Doloribus repellat voluptatem omnis ad laudantium velit. Etha Repellendus voluptas officia fugit rerum. Eaque et...
17 Molestiae non voluptas quisquam minus quia veritatis ipsam. Etha Quo nulla dolor optio at optio. Est explicabo volu...
16 Quasi ducimus quis a repellat. Ronaldo Numquam sunt incidunt molestiae omnis. Quis quis v...
15 Earum non fugit ut. Ronaldo Molestiae magnam atque quod distinctio placeat mol...
14 Quibusdam dolores hic magni neque possimus cumque. Enoch Quas mollitia et voluptate iste quo. Veniam volupt...
13 Similique qui quis dolorem quo et qui. Enoch Veniam voluptatem est debitis incidunt. Voluptatem...
12 Consequuntur qui quasi quo consequuntur corporis qui. Grayce Et saepe molestiae beatae aliquid optio quisquam....
11 Explicabo facere neque quo ipsam recusandae ab vero omnis. Grayce Culpa velit alias at quis repellendus. Repellendus...
tot.20

route



    Route
::get('/articles'ArticlesTable::class)
        ->
name('articles')
        ->
crumbs(fn ($trail) => $trail->parent('demo')->push('Articles'route('articles')));

component

Http/Livewire/ArticlesTable.php


<?php

namespace App\Http\Livewire;

use 
App\Models\Article;
use 
App\Models\Author;
use 
Zofe\Rapyd\Http\Livewire\AbstractDataTable;

class 
ArticlesTable extends AbstractDataTable
{
    public 
$search;
    public 
$author_id;

    public function 
getDataSet()
    {
        
$items Article::ssearch($this->search);
        if (
$this->author_id) {
            
$items $items->where('author_id''='$this->author_id);
        }

        return 
$items $items
            
->orderBy($this->sortField$this->sortAsc 'asc' 'desc')
            ->
paginate($this->perPage)
            ;
    }

    public function 
render()
    {

        
$items $this->getDataSet();
        
$authors Author::all()->pluck('firstname''id')->toArray();

        return 
view('livewire.articles.table'compact('items''authors'));
    }
}

view

../resources/views/livewire/articles/table.blade.php


<x-rpd::table
    
:items="$items"
>
    <
x-slot name="filters">
        <
div class="col">
            <
x-rpd::input debounce="350" model="search"  placeholder="search..." />
        </
div>
        <
div class="col">
            <
x-rpd::select lazy model="author_id" :options="$authorsplaceholder="author..." addempty />
        </
div>
    </
x-slot>

    <
x-slot name="buttons">
            <
a href="{{ route('articles') }}" class="btn btn-outline-dark">reset</a>
            <
a href="{{ route('articles.edit') }}" class="btn btn-outline-primary">add</a>
    </
x-slot>

    <
table class="table">
        <
thead>
        <
tr>
            <
th>
                <
x-rpd::sort model="id" label="id" />
            </
th>
            <
th>title</th>
            <
th>author</th>
            <
th>body</th>
        </
tr>
        </
thead>
        <
tbody>
        @foreach (
$items as $article)
            <
tr>
                <
td>
                    <
a href="{{ route('articles.view',$article->id) }}">{{ $article->id }}</a>
                </
td>
                <
td>{{ $article->title }}</td>
                <
td>{{ $article->author->firstname }}</td>
                <
td>{{ Str::limit($article->body,50) }}</td>
            </
tr>
        @endforeach
        </
tbody>
    </
table>

</
x-rpd::table>