| Id | Title | Author | Body | |
|---|---|---|---|---|
| Qui esse cupiditate eos amet. | Lindsay | Laborum rerum molestias in. Ut ab ipsum quisquam q... | ||
| Voluptas tenetur quis eum vitae consequatur. | Lindsay | Autem non exercitationem non distinctio illo modi... | ||
| Voluptas enim fugit sed nisi consequuntur voluptatem magni quis. | Amari | Ipsa reprehenderit ea perspiciatis ut praesentium.... | ||
| Quibusdam tenetur id minima quia id ut praesentium aut. | Amari | Deserunt unde voluptatum voluptate. Dolorem velit... | ||
| Deleniti et sit eius ut sed eum ut. | Hayley | Harum consequatur molestias est eum. Explicabo hic... | ||
| Facere in eveniet iste sapiente. | Hayley | Dolore id nam repellendus beatae dicta. Quis a qua... | ||
| Dolore aut ut qui dignissimos delectus. | Jacey | Eligendi tempore quas tempora reiciendis unde qui... | ||
| Aut itaque nobis suscipit dolor ipsum et et. | Jacey | Molestiae voluptatem rem consequatur. Accusantium... | ||
| Eius ad odit qui eveniet consectetur vel labore. | Helena | Enim est labore officiis optio illum eaque. Nulla... | ||
| Quod dolores fugiat molestiae in quas. | Helena | Non veniam et eveniet aperiam. Corrupti commodi co... |
demo-module/
├─ Livewire/
│ ├─ Home.php
│ ├─ ArticlesTable.php
│ ├─ ArticlesView.php
│ └─ ArticlesEdit.php
├─ Views/
│ ├─ home.blade.php
│ ├─ articles_table.blade.php
│ ├─ articles_view.blade.php
│ ├─ articles_edit.blade.php
│ ├─ menu.blade.php
│ └─ frontend_menu.blade.php
├─ Models/ Article.php, Author.php
├─ Database/ Migrations/, Seeders/
├─ config.php layout, menu entry
├─ routes.php
└─ DemoModuleServiceProvider.php
routes.php
Route::get('demo/articles', ArticlesTable::class)
->middleware(['web'])
->name('demo.articles')
->crumbs(fn ($crumbs) => $crumbs->parent('demo')->push(__('Articles'), route_lang('demo.articles')));
Livewire/ArticlesTable.php
<?php
namespace App\Modules\Demo\Livewire;
use App\Modules\Demo\Models\Article;
use App\Modules\Demo\Models\Author;
use Livewire\Component;
use Zofe\Rapyd\Traits\WithDataTable;
class ArticlesTable extends Component
{
use WithDataTable;
public string $search = '';
public ?int $author_id = null;
public function updatedSearch(): void
{
$this->resetPage();
}
public function updatedAuthorId(): void
{
$this->resetPage();
}
public function getDataSet()
{
return Article::ssearch($this->search)
->with('author')
->when($this->author_id, fn ($q) => $q->where('author_id', $this->author_id))
->orderBy($this->sortField, $this->sortAsc ? 'asc' : 'desc')
->paginate($this->perPage);
}
public function render()
{
return view('demo::articles_table', [
'items' => $this->getDataSet(),
'authors' => Author::query()->orderBy('firstname')->pluck('firstname', 'id')->toArray(),
])->layout('layout::admin');
}
}
Views/articles_table.blade.php
<x-rpd::card>
<x-rpd::table title="Articles" :items="$items">
<x-slot name="filters">
<x-rpd::input col="col" debounce="350" model="search" placeholder="search..." />
<x-rpd::select col="col-3" model="author_id" :options="$authors" placeholder="author..." addempty />
</x-slot>
<x-slot name="buttons">
<x-rpd::button route="demo.articles" color="outline-dark" label="Reset" />
<x-rpd::button route="demo.articles.edit" color="outline-primary" label="Add" />
</x-slot>
<table class="table">
<thead>
<tr>
<th><x-rpd::sort model="id" label="Id" /></th>
<th><x-rpd::sort model="title" label="Title" /></th>
<th>{{ __('Author') }}</th>
<th>{{ __('Body') }}</th>
<th></th>
</tr>
</thead>
<tbody>
@foreach ($items as $article)
<tr>
<td><x-rpd::nav-link :label="$article->id" route="demo.articles.view" :params="$article->id" /></td>
<td>{{ $article->title }}</td>
<td>{{ $article->author?->firstname }}</td>
<td>{{ Str::limit(strip_tags($article->body), 50) }}</td>
<td class="text-end"><x-rpd::icon name="edit" route="demo.articles.edit" :params="$article->id" /></td>
</tr>
@endforeach
</tbody>
</table>
</x-rpd::table>
</x-rpd::card>