I don't understand why you have:
$this->reservations = Reservation::all();
Yet you are paginating. Try calling the view again instead of back. Make sure you are using a spoofed post for the delete, not a get.
Hey everyone, I am struggling with issue about pagination. Problem is, that after i update any table and after updating table i do wanna go to previos page or to next page i am getting error The GET method is not supported for route livewire/update. Supported methods: POST and definetly it doesnt make sense to me. Record are updated in database but, after every updare or delete record from table, get method error happens.
This is my blade
<section>
<div class="container">
<div class="mt-5 text-center">
<h1>Rezervace</h1>
</div>
<div class="row mt-3">
@if ($reservations)
<div class="table-responsive">
<table class="table table-striped mt-5">
<thead>
<tr>
<th scope="col">Číslo rezervace</th>
<th scope="col">Celé jméno</th>
<th scope="col">Email</th>
<th scope="col">Čas rezervace</th>
<th scope="col">Telefonní číslo</th>
<th scope="col">Akce</th>
</tr>
</thead>
<tbody>
@foreach ($reservations as $reservation)
<tr>
<th scope="row">{{ $reservation->id }}</th>
<td>{{ $reservation->full_name }}</td>
<td>{{ $reservation->email }}</td>
<td>
{{ optional($reservation->availableBusinessHour)->formattedDayAndDate }}
od {{ optional($reservation->availableBusinessHour)->from }} do
{{ optional($reservation->availableBusinessHour)->to }}
</td>
<td>{{ $reservation->phone_number }}</td>
<td>
<button type="button" class="btn btn-danger btn-sm small-button"
wire:click="remove({{ $reservation->id }})"
wire:confirm="Jsi si jistý, že chceš záznam odstranit?">Odebrat</button>
</td>
</tr>
@endforeach
</tbody>
</table>
</div>
@else
<p>Žádné rezervace nejsou k dispozici.</p>
@endif
</div>
{{ $reservations->links('pagination::bootstrap-5') }}
</div>
</section>
And this is livewire component with logic
<?php
namespace App\Livewire\Forms;
use Livewire\Component;
use App\Models\Reservation;
use Livewire\WithPagination;
class Reserve extends Component
{
protected $layout = 'components.layouts.app';
private $reservations;
use WithPagination;
public function render()
{
return view('livewire.admin.reserve', [
'reservations' => Reservation::paginate(10),
]);
}
public function remove($id)
{
$reservation = Reservation::findOrFail($id);
$reservation->delete();
// Aktualizace dat
$this->reservations = Reservation::all();
session()->flash('success', 'Záznam byl úspěšně odstraněn.');
return back();
}
}
Thank you for every advice. :)
Problem solved, while i added this protected $paginationTheme = 'bootstrap'; into main component of blade
Please or to participate in this conversation.