php - Livewire handle Query

one text

Solution:

I'm assuming that you have a blade with an input like <input type="text" wire:model="name"/> to search by a name.

In your mount, you may want to pass the data from the request like this:

public function mount(Request $request)
{
   ...
    $this->name = request()->query('name');
   ...
}

And remove the responsability of the mount and add to a function like:

private search($name){            
    $this->response = $client->get(env('API_URL').'users?', [
        'query' => [
            'page'=> $page,
            'name'=> $name,
        ],
        'headers' => [
            'Authorization' => 'Bearer '. $value ,
            'Accept' => 'application/json',
        ],
    ]);
                
    $this->res = json_decode($this->response->getBody(), true);
}

Then you add a function that hear the changes from your input:

public function updatedName($name){
    $this->search($name);
}

The page query I'm not sure if you get them from the API or the query string. I suggest you look at the trait WithPagination if you're using models. If you're using the API pagination you will have to manual apply in the front the changes of the pages.

Source