Laravel append URI in route

You can append URI in route using comma separated array value to route. You can redirect to generated query string URL using redirect on controller action and using anchor tag in view file

Answers 1
  • Pass query string to url using named route in laravel

    <a href="{{ route('searchResult', ['keyword' => 'samar']) }}"> URL with query string </a>
    <a href="http://localhost:8000/search/all?keyword=samar" target="_blank" rel="noopener">http://localhost:8000/search/all?keyword=samar</a>
    //Step by step code implementation
    //# Create route in web.php
    use App\Http\Controllers\SearchController;
    Route::get('/search/all/', [SearchController::class, 'getAllSearchResult'])->name('searchResult');
    //Create SearchController if not exists with method getAllSearchResult
    php artisan make:controller SearchController
    //#Create controller method
    namespace App\Http\Controllers;
    use Illuminate\Http\Request;
    class SearchController extends Controller
        public function getAllSearchResult(){
  • Back to code snippet queries related laravel