Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

t0berius's avatar

livewire updating to v2.0

After updating from livewire 1.X to 2.X the following piece of code doesn't work anymore:

    switch (request()->query('filter', null)) {
        case 'affiliate':
            $this->authorize('view', AffiliateTransaction::class);
            $transactions = AffiliateTransaction::with(['user:id,name', 'order:id', ])->latest();
        break;
        case 'vendor':
            $this->authorize('view', VendorTransaction::class);
            $transactions = VendorTransaction::latest();
        break;
        //request to view general transactions for orders
        default:
            $this->authorize('view', GeneralTransactions::class);
            $transactions = GeneralTransactions::with(['order:id'])->latest();

Using v1the request()->query('filter') will be up to date all the time.

Using v2 the query will be set to null, after submitting the form the second time.

Any livewire experts here?

0 likes
3 replies
t0berius's avatar

I've fixed it, any improvements to my livewire code?

public $sortField = 'id';
public $sortAsc = false;
public $search = '';

public $requestSection;

public function mount($filter = null)
{
    $this->requestSection = request('filter', $filter);
}

public function sortBy($field)
{
    if ($this->sortField === $field) {
        $this->sortAsc = ! $this->sortAsc;
    } else {
        $this->sortAsc = true;
    }
    $this->sortField = $field;
}

public function render()
{
    switch ($this->requestSection) {
        case 'affiliate':
            $this->authorize('view', AffiliateTransaction::class);
            $transactions = AffiliateTransaction::with(['user:id,name', 'order:id', ])->latest();
        break;
        case 'vendor':
            $this->authorize('view', VendorTransaction::class);
            $transactions = VendorTransaction::latest();
        break;
        //request to view general transactions for orders
        default:
            $this->authorize('view', GeneralTransaction::class);
            $transactions = GeneralTransaction::with(['order:id'])->latest();
    }

    $search = $this->search;
//just attaching some sorty etc. ...

This code will keep the request part up to date inside the core (?filter=xyz).

Please or to participate in this conversation.