Laravel Get Current URL with Parameters Example

10-Apr-2023

.

Admin

Hi Developer,

In this comprehensive tutorial, we will learn get current url with parameters laravel. I’m going to show you about laravel get current url with query string. In this article, we will implement a laravel get current url in controller. you will learn get current url with parameters and segment method laravel example.

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...

#Laravel

#Laravel 6