Laravel & Php

How to Get Laravel Current Route Name, Full URL and Current URL


How to Get Laravel Current Route Name, Full URL and Current URL

To obtain the current URL and route name in Laravel, there are several methods available. In Laravel 8, you can use functions like current(), full(), request(), and url() to achieve this. Below is an example demonstrating how to obtain the current URL in Laravel:

//route name
request()->route()->getName()

//full() with Helper and Query string parameters
$currenturl = url()->full();
dd($currenturl);

//current() with Helper
$currenturl = url()->current();
dd($currenturl);

//using Request
$currenturl = Request::url();
dd($currenturl);

//current() with Facade
$currenturl = URL::current();
dd($currenturl);

//full() with Facade and Query string parameters
$currenturl = URL::full();
dd($currenturl);

//Get Previous URL in Laravel :
$pre_url= url()->previous();
dd($pre_url);

//Get Current Route in Laravel :
$cur_route = Route::current()->getName();
dd($cur_route);

Laravel
Share with Friends

Like this chef? Share with friends..