How to get current URL with parameters in Laravel ?

Share Me
  •  
  •  
  •  
  • 1
  •  
  •  
  •  
  •  
  •  
  •  
  •  
    1
    Share

Hello Dev’s, Today in this article, I will show you how to get current URL with parameters in laravel application. So from here you will get to current page URL and dynamic page get by URL with parameter also.

Now in this post, I will teach you how can we can get base url, current url with query string and also url segment in Laravel application.

While we are working with Laravel, we also need many times to get our current url and its segment. So we can get current url by using helper function URL::current().

To know how to get current URL without query string in Laravel Application

/**
* 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 can we 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 can we get url parameters in Laravel

we can easily get our url segment in Laravel application by using segment method. So Let’s assume we 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);
}

Read Also : Increment or decrement column value In Laravel example

Thanks for read. I hope it help you. For more you can follow us on facebook

About Shahriar Sagor

My name is Shahriar sagor. I'm a developer. I live in Bangladesh and I love to write tutorials and tips that will help to other Developer's. I am a big fan of PHP, Javascript, JQuery, Laravel, Codeigniter, VueJS, AngularJS and Bootstrap from the early stage.

View all posts by Shahriar Sagor →