How to get path from current URL in Laravel

Created at 05-Oct-2021 , By samar

How to get path from current URL in Laravel

In this session, we’ll try our hand at solving the "How to get path from current URL in Laravel" puzzle by using the computer language.

You can get path from current URL in Laravel using path() method on request() in Laravel. Path is URL without domain and query string value
  • Get path from current URL using request method in laravel

    request()->path()
    

    Output:

    get-all-users

    It returns the path of url (without domain and query string values). You can use above code snippet in web.php, controller files and also in views file in laravel.

    Here, we have web route to implement above code snippet.

    Route::get('get-all-users', [HomeController::class, 'getAllUsers']);

Back to code snippet queries related laravel

If you like what you are reading, please consider buying us a coffee ( or 2 ) as a token of appreciation.

Buy Me A Coffee

Don't forget to share this article! Help us spread the word by clicking the share button below.

We appreciate your support and are committed to providing you valuable and informative content.

We are thankful for your never ending support.