How to pass query string to url in laravel
Created at 07-Sep-2021 ,
By samar
How to pass query string to url in laravel
With this article, we will examine several different instances of how to solve the "How to pass query string to url in laravel".
You can pass query string to URL in laravel using named route and controller action. You can pass query string as comma separated array to named route and controller action and redirect to URL.-
Pass query string to url using named route in laravel
<?php <a href="{{ route('searchResult', ['keyword' => 'samar']) }}"> URL with query string </a> //Output <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 //app\Http\Controllers\SearchController.php <?php namespace App\Http\Controllers; use Illuminate\Http\Request; class SearchController extends Controller { public function getAllSearchResult(){ $getQueryString=\Request::fullUrl(); dd($getQueryString); } }
-
Pass query string to url using controller action in laravel
<?php action('SearchController@getAllSearchResult', ['keyword'=> 'samar']) //Output : <a href="http://localhost:8000/search/all?keyword=samar" target="_blank" rel="noopener">http://localhost:8000/search/all?keyword=samar</a> //Go to the generated query string URL using controller action. //#In controller’s method return redirect(action('SearchController@getAllSearchResult', ['keyword'=> 'samar'])); //#In view file <a href="{{ action('SearchController@getAllSearchResult', ['keyword'=> 'samar']) }}"> Action URL with Query string </a> //Step by step code implementation //# Create route in web.php use App\Http\Controllers\SearchController; Route::get('/search', [SearchController::class, 'getSearch'])->name('search'); Route::get('/search/all/', [SearchController::class, 'getAllSearchResult'])->name('searchResult'); //#Create SearchController if not exists with method getSearch and getAllSearchResult php artisan make:controller SearchController //#app\Http\Controllers\SearchController.php <?php namespace App\Http\Controllers; use Illuminate\Http\Request; class SearchController extends Controller { public function getSearch(){ return redirect(action('SearchController@getAllSearchResult', ['keyword'=> 'samar'])); } public function getAllSearchResult(){ $getQueryString=\Request::fullUrl(); dd($getQueryString); } } //On visit url <a href="http://localhost:8000/search/all?keyword=samar">http://localhost:8000/search</a> it will redirect you to url <a href="http://localhost:8000/search/all?keyword=samar">http://localhost:8000/search/all?keyword=samar</a>
If you like what you are reading, please consider buying us a coffee ( or 2 ) as a token of appreciation.
Don't forget to share this article! Help us spread the word by clicking the share button below.
We appreciate your support and are committed to providing you valuable and informative content.
We are thankful for your never ending support.
Random Code Snippet Queries: Laravel
- Create records using relationship in laravel
- Call to a member function pluck() on null
- How to pass two variables in HREF in laravel
- How to create new user without form submission in laravel
- Call to a member function getRelationExistenceQuery() on array in Laravel
- Array to string conversion laravel Controller
- How to add active class to menu item in laravel
- How to get images from AWS s3 and display in Laravel blade
- How to show data by ID in laravel?
- How to upload files to amazon s3 bucket using Laravel
- JQuery each loop on json response after ajax in laravel
- Sample configuration files to create laravel project with docker using wsl (window subsystem linux)
- How to create projects method with belongstomany relationship in user model
- Count all and get 10 records after where condition in laravel
- Laravel hasmany select not working
- Always load the relationship data with eager loading in Laravel
- OrderBy on Eloquent relationships method in Laravel
- Redirect to another view from controller in laravel
- The openssl extension is required for SSL/TLS protection but is not available
- Insert Comma Separated Values in laravel
- Input file with max size validation in laravel
- How to add class to tr in table using foreach in laravel
- Laravel specific table Migration
- How to get laravel errors folder in views directory in laravel
- If condition in foreach loop in laravel