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 Quod beatae aut et sit enim beatae ea. Damaris Maxime est quidem saepe quis vitae optio. Facilis...
19 Sed ex et ut. Damaris Rerum voluptates consequuntur id dolor consequuntu...
18 Laborum id ut ducimus ut. Deshawn Sed qui nostrum dolorem. Maiores exercitationem no...
17 Sequi possimus omnis sit sint facilis. Deshawn Id ipsa quia expedita veniam vel. Laborum esse cul...
16 Magnam eaque eum qui nam enim aut. Angelita Vel libero sit eos eaque qui incidunt cupiditate e...
15 Culpa porro sint minus sequi qui aliquam. Angelita Nemo qui aut amet et aut qui laudantium. Vitae et...
14 Et mollitia dolore inventore et dolor culpa. Alexanne Voluptas non iure accusamus molestiae. A vel debit...
13 Est aut sint sapiente accusantium aut et sit. Alexanne Omnis pariatur est minima veritatis. Expedita fugi...
12 Soluta id laborum esse est doloribus reprehenderit porro. Alysa Non sed vero fugiat ea perspiciatis omnis. Quam di...
11 Magnam sit consectetur accusantium iusto deleniti illum. Alysa Debitis perspiciatis dolore atque est sed. Fuga bl...
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>