| Id | Title | Author | Body | |
|---|---|---|---|---|
| 31460 | Nobis omnis dolores quia doloribus. | D'angelo | Corrupti vero et a et explicabo labore assumenda.... | |
| 31459 | Exercitationem omnis explicabo commodi accusantium sed est velit. | D'angelo | Totam sunt corrupti et. Repellendus veniam laudant... | |
| 31458 | Deserunt dolorem et deserunt dolorem blanditiis culpa. | Axel | Sunt iusto omnis esse. Quia et deleniti deleniti e... | |
| 31457 | Quaerat blanditiis possimus aut reiciendis. | Axel | Ut eaque sunt eius consequatur saepe. Est voluptas... | |
| 31456 | Et et suscipit omnis quas et autem. | Rebeca | Delectus ullam facilis voluptate quis voluptas sin... | |
| 31455 | Voluptas atque aperiam et velit nemo. | Rebeca | Ut rem placeat laboriosam et. Incidunt rerum aut s... | |
| 31454 | Ullam eligendi in est quis dolores. | Ricky | Eveniet corporis et quia odit est dolorem dolor. S... | |
| 31453 | Quis sed saepe id impedit. | Ricky | Dolor iusto est omnis. Sint est eos ex repellendus... | |
| 31452 | Blanditiis rem eaque nemo. | Aleen | Fuga cumque et modi animi praesentium blanditiis.... | |
| 31451 | Consequuntur nam deleniti et mollitia voluptas voluptatem. | Aleen | Corrupti amet amet enim nihil quisquam ea. Placeat... |
tot. 20
module structure
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
route
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')));
component
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');
}
}
view
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>