Raviya Technical
Published in

Raviya Technical

Laravel Livewire | Pagination Example

composer create-project --prefer-dist laravel/laravel blog
php artisan tinkerUser::factory()->count(100)->create()
composer require livewire/livewire
php artisan make:livewire user-pagination
app/Http/Livewire/UserPagination.phpresources/views/livewire/user-pagination.blade.php
<?phpnamespace App\Http\Livewire;use Livewire\Component;use Livewire\WithPagination;use App\Models\User;class UserPagination extends Component{use WithPagination;/*** Write code on Method** @return response()*/public function render(){return view('livewire.user-pagination', ['users' => User::paginate(10),]);}}
<div><table class="table-auto" style="width: 100%;"><thead><tr><th class="px-4 py-2">ID</th><th class="px-4 py-2">Name</th><th class="px-4 py-2">Email</th></tr></thead><tbody>@foreach ($users as $user)<tr><td class="border px-4 py-2">{{ $user->id }}</td><td class="border px-4 py-2">{{ $user->name }}</td><td class="border px-4 py-2">{{ $user->email }}</td></tr>@endforeach</tbody></table>{{ $users->links() }}</div>
Route::get('user-pagination', function () {return view('default');});
<!DOCTYPE html><html><head><title>Laravel Livewire Example - raviyatechnical</title>@livewireStyles<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/tailwindcss/1.9.0/tailwind.min.css" integrity="sha512-wOgO+8E/LgrYRSPtvpNg8fY7vjzlqdsVZ34wYdGtpj/OyVdiw5ustbFnMuCb75X9YdHHsV5vY3eQq3wCE4s5+g==" crossorigin="anonymous" /></head><body><div class="container"><div class="card"><div class="card-header">Laravel Livewire Example - raviyatechnical</div><div class="card-body">@livewire('user-pagination')</div></div></div></body>@livewireScripts</html>
php artisan serve
http://localhost:8000/user-pagination

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store