Home Laravel Laravel 8- Get Current URL in a Blade View Example

Laravel 8- Get Current URL in a Blade View Example

by Shahriar Sagor
Laravel 8- Get Current URL in a Blade View Example

Hello Dev’s Today now in this tutorial, I will share with you an example of how can we get url, or current url with query string and also url segment in Laravel application. Now Laravel has a lot of methods to help you with this example. So now they are all methods of Request and also can be called statically in Blade file without a problem. Here we know about how to get current URL in a Blade View.

So get current url or path in blade by using Request method. So the methods we can use for this are Request::url(), or Request::fullUrl(), or Request::path(), Request::is() and also Request::segment().

So here the following examples to laravel by get current url in a blade view:

Get the current path

By using the Request::path() method to get current path.

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


Path: post/demo
Get the current url

Now here by using the Request::url() method. It will return us the entire URL, but strip the query string from it.

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


Url: http://localhost:8000/post/demo
Get the current fullUrl

So here by using the Request::fullUrl() method. we probably won’t need this method very often, but it can prove to be useful.

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


FullUrl: http://localhost:8000/post/demo
Get current URL to Compare the a pattern

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

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


Is: true
Get only a segment of the current URL using the method

Now here by using the Request::segment() method to get current url to segment.


Segment: post

Read Also : Vue JS Get Array Length Or Object Length

I hope it will help you. Also you can follow us on Facebook


You may also like