Comparte:
No me funciona la paginación con Livewire
Hola, estoy haciendo la paginación de la tabla users usando {{ $users->links() }}, si no uso "use WithPagination" en el controlador de Livewire funciona recargando toda la página. Si lo pongo no cambia de página
\app\Http\Livewire\UsersTable.php
<?php
\app\Http\Livewire\UsersTable.php
<?php
namespace App\Http\Livewire;
use App\Models\User;
use Livewire\Component;
use Livewire\WithPagination;
class UsersTable extends Component
{
/use WithPagination;
public function render()
{
return view('livewire.users-table',[
'users' => User::paginate(5)
]);
}
}
La vista \resources\views\users\show.blade.php contiene
<slot name="header">
La vista \resources\views\users\show.blade.php contiene
<slot name="header">
<h1>Listado de usuarios</h1>
<h2 class="font-semibold text-xl text-gray-800 leading-tight">
{{ __('User') }} Livewire
</h2>
</slot>
<livewire:users-table>
</livewire:users-table>
y el componente \resources\views\livewire\users-table.blade.php
<div>
<x-slot name="header">
<h2 class="font-semibold text-xl text-gray-800 leading-tight">
{{ __('User') }} Livewire
</h2>
</x-slot>
<div class="flex flex-col mt-10">
<div class="-my-2 overflow-x-auto sm:-mx-6 lg:-mx-8">
<div class="py-2 align-middle inline-block min-w-full sm:px-6 lg:px-8">
<div class="shadow overflow-hidden border-b border-gray-200 sm:rounded-lg">
<table class="min-w-full divide-y divide-gray-200">
<thead class="bg-gray-50">
<tr>
<th scope="col" class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Image</th>
<th scope="col" class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Nombre</th>
<th scope="col" class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Correo</th>
<th scope="col" class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Equipos</th>
<th scope="col" class="relative px-6 py-3">
<span class="sr-only">Edit</span>
</th>
</tr>
</thead>
<tbody>
@foreach ($users as $user)
<tr>
<td class="px-6 py-4 whitespace-nowrap">
<img class="h-12 w-12 flex-none rounded-full bg-gray-50" src="{{ $user->profile_photo_url }} alt="{{ $user->name }}">
</td>
<td class="px-6 py-4 whitespace-nowrap">
<p class="text-sm font-semibold leading-6 text-gray-900">{{ $user->name }}</p>
</td>
<td class="px-6 py-4 whitespace-nowrap">
<p class="mt-1 truncate text-xs leading-5 text-gray-500">{{ $user->email }}</p>
</td>
<td class="px-6 py-4 whitespace-nowrap">
<p class="text-sm leading-6 text-gray-900">{{ $user->allTeams()->pluck('name')->join(', ')}}</p>
</td>
</tr>
@endforeach
</tbody>
</table>
<div class="px-6 py-4 whitespace-nowrap">
{{ $users->links() }}
</div>
</div>
</div>
</div>
</div>
</div>
El fichero de rutas es básico
<?php
El fichero de rutas es básico
<?php
use App\Http\Livewire\UsersTable;
use Illuminate\Support\Facades\Route;
use App\Models\User;
/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider and all of them will
| be assigned to the "web" middleware group. Make something great!
|
*/
Route::get('/', function () {
return view('welcome');
});
Route::middleware([
'auth:sanctum',
config('jetstream.auth_session'),
'verified'
])->group(function () {
Route::get('/dashboard', function () {
return view('dashboard');
})->name('dashboard');
Route::get('/users', UsersTable::class)->name('users');
});
Estoy usando la versión 10 de Laravel, PHP 8.2.8 y Livewire 2.11
No encuentro el motivo a este comportamiento. Gracias si alguien tiene alguna idea.
Estoy usando la versión 10 de Laravel, PHP 8.2.8 y Livewire 2.11
No encuentro el motivo a este comportamiento. Gracias si alguien tiene alguna idea.