Laravel get current URL path – How to get Current url path?

Laravel get current URL path Using Request::url(), Request::fullUrl(), Request::path(), Request::segment() and {{ Request::is(‘article/*’) }} Examples.

Laravel get current URL path

Get the current URL without the query string. The methods we can use for this are Request::url() , Request::fullUrl() , Request::path() , Request::is() and Request::segment() .

using the Request::url() method

@if (Request::url() == 'some string')
	// Here Best Busineess Logic
@endforeach

using the Request::fullUrl()
Get the current fullUrl

@if (str_contains(Request::fullUrl(), 'some-string'))
	// Here Best Busineess Logic
@endif

Get Current URL in a Blade View

How to get current URL or path in Blade?

@if (Request::path() == '/article-title')
	// Here Best Busineess Logic
@endif

Don’t Miss : Get Current URL In A Blade View Using Laravel

using the method Request::segment()

// Returns true for domain_name.com/api/article and false for domain_name.com/api/edit
@if (Request::segment(2) == 'article')
	// Here Best Busineess Logic
@endif

Laravel – Get Current URL in a Blade View Example

Get only a segment of the current URL using the method

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

//Results

Segment: article

Get current URL to Compare the a pattern

Read Also:  how to check empty array in laravel controller?

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

I hope you get an idea about Laravel get current URL path.
I would like to have feedback on my infinityknow.com blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.