jakubjv's avatar

Livewire Pagination The GET method is not supported

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. :)

0 likes
7 replies
jlrdw's avatar

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.

jakubjv's avatar

@jlrdw ye you had true that there were few things which dont make sense,, i did refactor like this

<?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();


        session()->flash('success', 'Záznam byl úspěšně odstraněn.');


    }


}

and still after delete record when i go to another page i am getting The GET method is not supported for route livewire/update. Supported methods: POST.

jlrdw's avatar

@jakubjv You are passing id in the query string, or as a parameter?

It shouldn't be in the url.

jlrdw's avatar

@jakubjv referring to $reservation

A delete should be a spoofed POST.

jakubjv's avatar
jakubjv
OP
Best Answer
Level 2

Problem solved, while i added this protected $paginationTheme = 'bootstrap'; into main component of blade

Please or to participate in this conversation.