id | title | author | body |
---|---|---|---|
10 | Magnam eos enim ipsam voluptas sit quibusdam. | Makenzie | Quaerat facilis sit vitae qui ut amet. Ut nam volu... |
9 | In accusantium odio quis culpa sed culpa sed. | Makenzie | Modi et illum consequatur quas aspernatur. Dolorem... |
8 | Libero nobis et sunt libero iusto fugiat molestias. | Alejandrin | Illum quis beatae omnis delectus qui porro. Maiore... |
7 | Blanditiis hic consequatur minus dignissimos. | Alejandrin | Similique neque excepturi non iusto. Velit quod do... |
6 | Est ut sit dignissimos vel qui. | Darian | Sapiente reiciendis sed ut nemo. Delectus ut repel... |
5 | Voluptas temporibus numquam placeat nobis accusamus et adipisci. | Darian | Ratione illo harum quo perferendis. Totam placeat... |
4 | Harum aspernatur voluptatem reprehenderit est. | Randal | Sit aut quos provident nobis voluptas est aut. Ab... |
3 | Voluptate beatae hic unde aspernatur. | Randal | Quis eaque voluptate distinctio rerum. In vitae et... |
2 | Quaerat ad id numquam voluptas odit voluptas voluptas voluptas. | Zander | Aut commodi dolor quo fugiat aut voluptatem enim.... |
1 | Et veniam deleniti tenetur animi ut id. | Zander | Ut aspernatur quisquam tempore dolor nam ducimus v... |
tot. 20
module structure
laravel/
├─ app/
│ ├─ Modules/
│ │ ├─ Demo/
│ │ │ ├─ Livewire/
│ │ │ │ ├─ Articles/
│ │ │ │ │ ├─ views/
│ │ │ │ │ │ ├─ articles_edit.blade.php
│ │ │ │ │ │ ├─ articles_table.blade.php
│ │ │ │ │ │ ├─ articles_view.blade.php
│ │ │ │ │ ├─ ArticlesEdit.php
│ │ │ │ │ ├─ ArticlesTable.php
│ │ │ │ │ ├─ ArticlesView.php
│ │ │ │ ├─ routes.php
route
Livewire/routes.php
Route::get('demo/articles', ArticlesTable::class)
->middleware(['web'])
->name('demo.articles')
->crumbs(fn ($crumbs) => $crumbs->parent('demo')->push('Articles', route('demo.articles')));
component
Livewire/Articles/ArticlesTable.php
<?php
namespace App\Modules\Demo\Livewire\Articles;
use App\Modules\Demo\Models\Author;
use App\Modules\Demo\Models\Article;
use Zofe\Rapyd\Traits\WithDataTable;
use Livewire\Component;
class ArticlesTable extends Component
{
use WithDataTable;
public $search;
public $author_id;
public function updatedAuthorId()
{
$this->resetPage();
}
public function updatedSearch()
{
$this->resetPage();
}
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('demo::Articles.views.articles_table',
compact('items','authors')
)->layout('demo::admin');
}
}
view
Livewire/Articles/views/articles_table.blade.php
<x-rpd::card>
<x-rpd::table
title="List Articles"
:items="$items"
>
<x-slot name="filters">
<x-rpd::input col="col" debounce="350" model="search" placeholder="search..." />
<x-rpd::select col="col" lazy model="author_id" :options="$authors" placeholder="author..."
addempty />
</x-slot>
<x-slot name="buttons">
<a href="{{ route('demo.articles') }}" class="btn btn-outline-dark">reset</a>
<a href="{{ route('demo.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('demo.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>
</x-rpd::card>