
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.
Answers 2
-
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); } }
0 -
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>
0
Random Code Snippet Queries: Laravel
- Get only 10 records from table in laravel
- How to fetch single row data from database in laravel
- How to add active class to menu item in laravel
- How to increment column value of table in Laravel
- Remove several global scope from query
- How to customize or Change validation error messages
- Declaration of App\Models\Post::sluggable() must be compatible with Cviebrock\EloquentSluggable\Sluggable
- Store logged in user details in session and display in view in laravel
- Show old value while editing the form in Laravel
- Laravel recursive function in controller
- Global scope in Laravel with example
- How to Access Array in blade laravel
- Property [user] does not exist on this collection instance
- After image selected get validation error in laravel
- Session Doesn't Work on Redirect
- Get laravel version
- Json encode method in laravel
- How to create controller in laravel
- How to get records in random order in laravel
- How to pass external link in laravel blade to anchor tag
- Route [password.request] not defined
- How to validate website url in laravel using validaiton
- Illuminate\Database\QueryException could not find driver
- How to get only time from created_at in laravel
- How to get CSRF token in laravel controller