How to get current URL in Laravel blade file

Laravel get current URL in blade Example; In this tutorial, we will show you how to get current url, current url with query string and url segment in Laravel blade. Laravel has a lot of methods to get these type from url. You can get the all these type urls from Request in Blade any problems.

Lets see the following example to laravel get current url in a blade view file.

Get the current path

You can get the current path using Request::path() method in blade file.

<p> Current Path: {{ Request::path() }} </p>

Get the current url

For getting current url just just Request::url() method just like below:

<p> Current Url: {{  Request::url() }} </p>

Get the current fullUrl

If you want to get the full url in blade file then use the Request::fullUrl() method.

<p> FullUrl: {{ Request::fullUrl() }} </p>

Get current URL to Compare the a pattern

here using the Request::is() method. You can even use the * wildcard. It will return true if a match is found.

<p> Is: {{ Request::is('post/*') }} </p>

Get segment of the current URL

Request::segment() method to get current url to segment.

First Segment:

If you pass 1 inside the segment then its return first segment.

<p> First Segment: {{ Request::segment(1) }} </p>

Second Segment:

If you pass 2 inside the segment then its return second segment. just same you can use 3 4 etc.

<p> First Segment: {{ Request::segment(2) }} </p>

I hope this example help you…

Leave a Comment