Laravel Get Current URL with Parameters Example
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...
- How to Notifications With database Driver in Laravel 11?
- How to Send Email Via Notification in Laravel 11?
- How to Install and Configure Laravel 11 Debugbar?
- How to Like Dislike System in Laravel 11?
- How to Paginate a Model with Relationship in Laravel 11?
- Laravel 11 Upload Files to Amazon S3 Example
- Laravel 11 Send WhatsApp Messages Example
- Laravel 11 Rest API Authentication Using JWT Tutorial