Hii Guys,
In this Example, I will learn you to get current url with query string laravel 6. we can simply get current full url using Request in laravel 6 application.
I need many times to get current url and query string, you can get url query string by using helper function \Request::fullUrl().
Step1:Create Route
you Will create to route routes/web.php in file.
Route::get('/route',"[email protected]")->name('route.test');
Step2:Create Controller
you Will create to controller app/Http/RouteController.php in file.
php artisan make:controller RouteController
Example 1:
I will use the fullUrl() method in this example.
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function index(Request $request)
{
$getQueryString=\Request::fullUrl();
dd($getQueryString);
}
Output
"http://localhost:8000/route?id=1&name=keval"
Example 2:
I will use the getRequestUri() method in this example.
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function index(Request $request)
{
$getQueryString=\Request::getRequestUri();
dd($getQueryString);
}
Output
"http://localhost:8000/route?id=1&name=keval"
Example 3:
I will use the url()->full() method in this example.
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function index(Request $request)
{
$getQueryString=url()->full();
dd($getQueryString);
}
Output
"http://localhost:8000/route?id=1&name=keval"
It will help you.....