| Id | Titolo | Autore | Testo | |
|---|---|---|---|---|
| 3980 | Non aut incidunt est reprehenderit. | Garfield | Facilis rem ut ab assumenda aut aut delectus. Cum... | |
| 3979 | Praesentium eum laudantium deleniti mollitia. | Garfield | Placeat consectetur iste rerum blanditiis dolorem... | |
| 3978 | Numquam maxime dolore id aut. | Hilma | Cupiditate possimus earum ut ex omnis fuga vitae.... | |
| 3977 | Vitae ut deleniti velit ut tenetur eveniet. | Hilma | Sint iste et ut molestiae. Similique quo minus et... | |
| 3976 | Magni ea aperiam voluptas esse eum voluptas. | Gillian | Non illum tempore tempora magni tenetur iure dolor... | |
| 3975 | Id voluptate dolorum rerum dolore est. | Gillian | Officia et delectus neque qui a aperiam esse. Ea n... | |
| 3974 | Quidem quasi magni aliquid sapiente. | Luna | Nesciunt voluptatem sit quos similique odit soluta... | |
| 3973 | Error sunt repudiandae enim assumenda facere. | Luna | Qui qui ut non. Ad quos mollitia ex vel ut qui cor... | |
| 3972 | Possimus quisquam consequuntur consequatur tenetur quia et adipisci. | Marcella | Sint laboriosam error sit deserunt aut facilis ad.... | |
| 3971 | Voluptatem laudantium molestiae alias aut. | Marcella | Ab consectetur facere dolores cupiditate quas. Dol... |
tot. 20
struttura del modulo
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')));
componente
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>