Level 70
You can use append() all queries GET parameters into pagination link like this way-
{{ $users->appends($_GET)->links() }}
1 like
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
I wana pass search query to laravel view, for now i try use compact and compatct-> with but still results it's this same "Undefined variable: query"
I try pass hard code like single query "abc" , "bcd" etc. it's work /kategoria?query=abc&page=2, but when i wana make some like wildcart then i cant pass variable query to view.
Search Controller function
public function kategorie(Request $request)
{
$query = $request->input('query');
$pages = Page::where('kategoria', 'like', "%$query%")
->orWhere('tags', 'like', "%$query%")
->paginate(5);
return view('kategoria')->compact('pages')->with('query', $query);
}
View pagination output (it's work but i need search results not abc)
{{ $pages->appends(['query' => 'abc' ])->links() }}
View pagination with variable and don't work :/
{{ $pages->appends(['query' => $query ])->links() }}
ErrorException {#745 ▼
#message: "Undefined variable: query"
#code: 0
#file: "/home/mitek91/domains/test91.vot.pl/public_html/obito/storage/framework/views/653b682019bed23b6b130f5076f5c885047247fb.php"
#line: 1
#severity: E_NOTICE
}
You can use append() all queries GET parameters into pagination link like this way-
{{ $users->appends($_GET)->links() }}
Please or to participate in this conversation.