datarecall's avatar

Livewire Filters

I am converting some of my pages to livewire components I have this filter based on the filters the episodes for the Forum TDD series this is my livewire component:

<?php

namespace App\Http\Livewire;

use App\Channel;
use App\Filters\ThreadFilters;
use App\Queries\ThreadQuery;
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
use Livewire\Component;
use Livewire\WithPagination;

class ForumHome extends Component {

    use WithPagination, AuthorizesRequests;

    public $channel;

    private $filters;

    public function mount(Channel $channel, ThreadFilters $filters)
    {
        $this->channel = $channel;
        $this->filters = $filters;
    }

    public function render()
    {
        $threads = ThreadQuery::getThreads($this->channel, $this->filters);

        return view('livewire.forum.home', [
            'threads' => $threads
        ]);
    }

}

On the first page load, this works fine and thread filters is set on the initial load if I dump($this->filters); in the render method it displays: https://share.getcloudapp.com/ApuL6B1d

Since this is using pagination when I click next page I get the error:

Argument 2 passed to App\Queries\ThreadQuery::getThreads() must be an instance of App\Filters\ThreadFilters, null given, called in /home/vagrant/code/gd/app/Http/Livewire/ForumHome.php on line 31

The error seems right since my threadQuery is setup like:

public static function getThreads(Channel $channel, ThreadFilters $filters){

I just don't know why its not keeping the data consistent when $this->filters is being set on mount().

0 likes
0 replies

Please or to participate in this conversation.