Get Current URL in a Blade View using Laravel

Today, We want to share with you laravel get current url.In this post we will show you get current url in laravel 6, laravel 7 and laravel 8 application., hear for Laravel – How to get current URL in controller or view? we will give you demo and example for implement.In this post, we will learn about Laravel 5.8 get current url with parameters with an example.

Read Also:  PHP mysqli insert update delete for Dynemic query

How to get current URL or path in Blade?

Example 1: Get the current path

@if (Request::path() == '/post-title')
	// Do something

Example 2: Compare the current URL to a pattern

@if (Request::is('apirest/*'))
	// Do something

Example 3: Get only a segment of the current URL

// Returns true for and false for
@if (Request::segment(2) == 'post')
	// Do something

Example 4: Get the URL without query string

@if (Request::url() == 'some string')
	// Do something

Example 5: Get the full URL, including query string

@if (str_contains(Request::fullUrl(), 'some-string'))
	// Do something

Get Current Route in Laravel:

$route = Route::current()->getName();

Get Previous URL in Laravel:

$url = url()->previous();

Example : using Request

$currentURL = Request::url();

using full() with Facade(with query string parameters)

$currentURL = URL::full();

current() with Facade

currentURL = URL::current();

full() with Helper(with query string parameters)

$currentURL = url()->full();

current() with Helper

$currentURL = url()->current();

I hope you get an idea about get current URL anywhere.
I would like to have feedback on my 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.

Read Also:  Laravel Get Absolute Path Document Root Base URL

About Pakainfo

I am Jaydeep Gondaliya, a software engineer, the founder and the person running Pakainfo. I'm a full-stack developer, entrepreneur and owner of I live in India and I love to write tutorials and tips that can help to other artisan, a Passionate Blogger, who love to share the informative content on PHP, Javascript, JQuery, Laravel, Codeigniter, VueJS, AngularJS and Bootstrap from the early stage.

View all posts by Pakainfo →

Leave a Reply

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