Laravel 6 , Laravel
Nicesnippets
5361
24-09-2019
hi guys,
In this post,we will learn get to current URL with parameters in laravel 6.you will get to current page URL and dynamic page get URL with parameter.
In this post, I will tell you how can you get base url, current url with query string and url segment in Laravel.
While working with Laravel, i need many times to get current url and its segment, you can get current url by using helper function URL::current().
How to get current URL without query string in Laravel
/**
* Show the application dashboard.
*
* @return \Illuminate\Contracts\Support\Renderable
*/
public function index()
{
$url = \URL::current();
dd($url);
}
/**
* Show the application dashboard.
*
* @return \Illuminate\Contracts\Support\Renderable
*/
public function index()
{
$url = \Request::url();
dd($url);
}
How to get current URL with query string in Laravel
/**
* Show the application dashboard.
*
* @return \Illuminate\Contracts\Support\Renderable
*/
public function index()
{
$url = \Request::fullUrl();
dd($url);
}
How to get url parameters in Laravel
You can easily get your url segment in Laravel by using segment method. Let's assume i have a url with some query string.
www.nice.com/blogs?page=2
/**
* Show the application dashboard.
*
* @return \Illuminate\Contracts\Support\Renderable
*/
public function index()
{
$url = \Request::segment(3);
dd($url);
}
It will help you...