How do I get the current URL path in Laravel8

Published January 17, 2022

It is pretty easy to get the current Url  Path in Laravel 8. Just follow these steps

Step 1: Set up a new Laravel project by running the following command on the composer

composer create-project --prefer-dist laravel/laravel url_path


Laravel get url of the project

Laravel files will be generated in a new folder, "url_path."


Laravel8 get URL path


Step 2:  Our laravel project has been created. Go to in your browser to see this page:


Laravel8 get url path of the current project

 Step 3: To display our current URL path, we need to do this. Add the following code to your welcome.blade.php file:


Laravel get current project url path



        <meta charset="utf-8">

        <meta name="viewport" content="width=device-width, initial-scale=1">


        <!-- Fonts -->

        <link href=";600;700&display=swap" rel="stylesheet">

        <!-- Styles -->


            body {

                font-family: 'Nunito', sans-serif;




<body class="antialiased">


// this line gets the Current Filename.

$currentPage= $_SERVER['SCRIPT_NAME'];

// this line gets the directory name where file have been stored

$currentPage = substr($currentPage, 1);

// this line displays the current Filename

echo $currentPage;





Step 4: To see your URL path, go to in your web browser


That’s it, our URL path is displayed on our screen.



Download Source code


Article Contributed By :