
How to pass query string to url in laravel
Created at 06-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('[email protected]', ['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('[email protected]', ['keyword'=> 'samar'])); //#In view file <a href="{{ action('[email protected]', ['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('[email protected]', ['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
- Retrieve count of nested relationship data in Laravel
- Get duplicate records in laravel
- How to create belongstomany relation using custom name on custom pivot table
- How to get file extension from input type file in laravel
- Create model with migration and seeder
- How to delete record in Laravel with ajax
- Return view from route Laravel
- Target class [admin] does not exist.
- Trying to access array offset on value of type null error in laravel
- How to pass link from controller to view in laravel on ajax call
- How to check query string exists or not in laravel blade
- How to include header file in laravel
- How to display validation error in laravel
- How to send email in laravel
- How to get route method name in Laravel
- Ajax GET request in laravel
- Get current URL on visit URL in Laravel
- Validation for multiple forms on same page in laravel
- Call to undefined relationship [user] on model [App\Models\Post]
- Laravel route redirect not working
- Get comma separated email from input array
- SQLSTATE[23000]: Integrity constraint violation: 1022 Can't write; duplicate key in table
- How to set column as primary key in Laravel model
- Update record after find method in lavavel
- Database transactions in laravel