List Articles

id title author body
20 Et est fugiat fugiat odit nisi culpa. Roma Itaque aut deserunt rerum. Quo dignissimos aut quo...
19 Dolorem ipsum cum dolorem et. Roma Consequatur numquam aut nemo. Voluptatibus numquam...
18 Odio quia labore ipsa vel quos rem ut. Jodie Sed magnam rerum aut officia sit impedit quo odit....
17 Consequatur minus non aut consequatur soluta sit. Jodie Nihil ut quibusdam nihil commodi. Qui qui sunt quo...
16 Aut tempore et est eveniet omnis. Deontae Voluptatibus doloribus neque aut ipsam nemo adipis...
15 Est dolores consequatur voluptatem doloremque possimus voluptatibus. Deontae Quae ipsam est qui. Beatae nostrum quam quasi est...
14 Amet sapiente minima nemo molestiae nemo. Pierre Sit eum corrupti voluptatem optio. Quo commodi pra...
13 Qui et illo quaerat aut consequuntur. Pierre Id totam harum voluptatem autem molestias. Itaque...
12 Expedita alias doloremque quis qui. Torrance Quae voluptatem ut nam qui ex. Consequatur recusan...
11 Unde a voluptate optio officiis ut tempore. Torrance Laboriosam explicabo vel at. Voluptatem qui commod...
tot.20

module structure


laravel/
├─ app/
│  ├─ Modules/
│  │  ├─ Demo/
│  │  │  ├─ Components/
│  │  │  │  ├─ Articles/
│  │  │  │  │  ├─ views/
│  │  │  │  │  │  ├─ articles_edit.blade.php
│  │  │  │  │  │  ├─ articles_table.blade.php
│  │  │  │  │  │  ├─ articles_view.blade.php
│  │  │  │  │  ├─ ArticlesEdit.php
│  │  │  │  │  ├─ ArticlesTable.php
│  │  │  │  │  ├─ ArticlesView.php
│  │  │  │  ├─ routes.php

route

Components/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

Components/Articles/ArticlesTable.php


<?php

namespace App\Modules\Demo\Components\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

Components/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="$authorsplaceholder="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>