I just wanted to write how I have fixed this.
The problem is, that Livewire keeps the state of your pagination even when you update your component.
The search works flawlessly when you are on page 1.
If you are on a page other than 1 your url state is still perserved and so the search wont work.
For this to work you have to set a lifecycle hook when updating your public property, so that you can set it everytime to page 1.
If you do that everything will work without a problem.
Controller:
<?php
namespace App\Http\Livewire\Tags;
use App\Tag;
use Exception;
use Illuminate\Contracts\View\Factory;
use Illuminate\View\View;
use Livewire\Component;
use Livewire\WithPagination;
class TagEdit extends Component
{
use WithPagination;
public $searchInput;
private $pagination = 5;
/**
* @param $id
* @throws Exception
*/
public function deleteTags($id): void
{
$deleteID = Tag::findOrFail($id);
$deleteID->delete();
}
/**
* Livewire Lifecycle Hook
*/
public function updatingSearchInput(): void
{
$this->gotoPage(1);
}
/**
* @return Factory|View
*/
public function render()
{
return view('livewire.tags.tag-edit', [
'searchList' => Tag::where('schlagwort', 'like', '%' . trim($this->searchInput) . '%')
->orderBy('created_at', 'desc')->paginate($this->pagination),
]);
}
}
View:
<div xmlns:wire="http://www.w3.org/1999/xhtml">
<div class="text-left mb-5">
<label for="labelSchlagwort" class="font-weight-bold">Schlagwort Suchen:</label>
<input class="form-control" placeholder="Schlagwort Suchen" type="text" wire:model="searchInput">
</div>
@if($searchList->total() > 0)
<div class="container">
{{ $searchList->links() }}
<table class="table table-striped table-hover">
<thead>
<tr>
<th scope="col" class="text-left">Schlagwort</th>
<th scope="col" class="text-left">Angelegt am</th>
<th scope="col" class="text-left"></th>
</tr>
</thead>
<tbody>
@foreach($searchList as $searchedItem)
<tr>
<td class="text-left">{{ $searchedItem->schlagwort }}</td>
<td class="text-left">{{ $searchedItem->created_at }}</td>
<td class="text-left">
<button class="btn btn-success">Editieren</button>
<button class="btn btn-danger" wire:click="deleteTags({{ $searchedItem->id }})">
Löschen
</button>
</td>
</tr>
@endforeach
</tbody>
</table>
{{ $searchList->links() }}
</div>
@endif
</div>
Hope this helps other people that are having the same issue.