How to get path from current URL in Laravel

Updated at 04-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