LaravelTutorials

Laravel 8 – Get Current URL in a Blade View

Divi WordPress Theme

How can you get url, current url with query string and url segment in Laravel. Laravel has a lot of methods to help get current url. All methods of Request and can be called statically in Blade without a problem.

Get current url or path in blade using Request method The methods we can use for this are Request::url(), Request::fullUrl(), Request::path(), Request::is() and Request::segment().

Request::path() method to get current path:

Path: {{ Request::path() }}

Output:

Path: post/demo

Get the current url:

Url: {{  Request::url() }}

Output:

Url: http://localhost:8000/post/demo

Get the current fullUrl:

FullUrl: {{ Request::fullUrl() }}

Output:

FullUrl: http://localhost:8000/post/demo

Get current URL to Compare the a pattern:

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

Output:

Is: true

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

Segment: {{ Request::segment(1) }}

Output:

Segment: post

Thank you for reading this tutorial. If any problem please feel free to contact me.

Khandoker Hirok

I'm an expert web developer over 6 years experience. I can fix bugs, customize and makes website and Software as per your requirements with Wordpress, PHP, Laravel and Codeigniter. My Fiverr: https://fiverr.com/hirokbd

Related Articles

Leave a Reply

Your email address will not be published. Required fields are marked *

Back to top button