my fix for now is adding a hidden field with the get value to each form:
@if(isset($_GET['q']))
<input type="hidden" value="{{ $_GET['q'] }}" name="q" id="q">
@endif
But isn't there a nicer way?
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
Hello guys,
so i have a table with users and i've added some filters with local scopes
User.php
public function scopeSearch($query, $search)
{
if (isset($search)) {
return $query->where('id', 'like', '%' . $search . '%')->orWhere('name', 'like', '%' . $search . '%')->orWhere('email', 'like', '%' . $search . '%');
}
return $query;
}
public function scopeSelection($query, $selection)
{
if (isset($selection)) {
switch ($selection) {
case 1:
return $query->withTrashed();
break;
case 2:
return $query;
break;
case 3:
return $query->onlyTrashed();
break;
}
}
}
public function scopeAmount($query, $amount)
{
if (isset($amount)) {
return $query->paginate($amount);
}
return $query->paginate(10);
}
In my UsersController @ index im calling these filters like this
$users = User::search($request->q)->selection($request->selection)->amount($request->amount);
And in my index.blade.php i have to forms, one for the search field and one for the selection and amount (2 selects)
<form action="{{ route('users.index') }}" type="get">
<input class="uk-input uk-width-medium uk-border-rounded uk-box-shadow-small" id="q" name="q" value="{{ isset($_GET['q']) ? $_GET['q'] : "" }}" type="search" placeholder="Suche">
</form>
{{-- Form --}}
<form action="{{ route('users.index') }}" method="GET">
{{-- Grid --}}
<div uk-grid>
{{-- Anzahl --}}
<div class="uk-width-1-3">
<span>Anzahl</span>
</div>
<div class="uk-width-2-3">
<select class="uk-select" name="amount" id="amount">
<option {{ (isset($_GET['amount']) && $_GET['amount'] == 10) ? 'selected' : "" }} value="10">10</option>
<option {{ (isset($_GET['amount']) && $_GET['amount'] == 25) ? 'selected' : "" }} value="25">25</option>
<option {{ (isset($_GET['amount']) && $_GET['amount'] == 50) ? 'selected' : "" }} value="50">50</option>
</select>
</div>
{{-- /Anzahl --}}
{{-- HR --}}
<div class="uk-width-1-1"><hr/></div>
{{-- /HR --}}
{{-- Auswahl --}}
<div class="uk-width-1-3">
<span>Auswahl</span>
</div>
<div class="uk-width-2-3">
<select class="uk-select" name="selection" id="selection">
<option {{ (isset($_GET['selection']) && $_GET['amount'] == 1) ? 'selected' : "" }} value="1">Aktiv</option>
<option {{ (isset($_GET['selection']) && $_GET['amount'] == 2) ? 'selected' : "" }} value="2">Inaktiv</option>
</select>
</div>
{{-- /Auswahl --}}
{{-- Button --}}
<div class="uk-width-1-1">
<button class="uk-button uk-button-link uk-text-muted uk-align-right" type="submit"><i class="fas fa-sync-alt"></i></button>
</div>
{{-- /Button --}}
</div>
{{-- /Grid --}}
</form>
{{-- /Form --}}
For design reasons i cant but them in one form field, now im struggling to append the params to each form. For example when i have set filters for amount and selection the url looks like this
http://localhost/?selection=2&amount=25
But when i then search something with the search field these 2 params will get removed (selection & amount) and the url will look like this
http://localhost/?q=name
How can i append the params to each form submission?
I hope you guys know what i mean, my english isn't the best i know..
Thanks in advance!
Please or to participate in this conversation.