How to get path from current URL in Laravel
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']);
If you like what you are reading, please consider buying us a coffee ( or 2 ) as a token of appreciation.
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.
Random Code Snippet Queries: Laravel
- Store logged in user details in session and display in view in laravel
- SQLSTATE[42000]: Syntax error or access violation: 1075 Incorrect table definition; there can be only one auto column and it must be defined as a key
- Retain selected value of select box in Laravel
- Update record after find method in lavavel
- How to prevent host header attack in Laravel
- Argument 1 passed to Illuminate\Database\Query\Builder::cleanBindings() must be of the type array, null given
- Calculate age from date of birth in Laravel
- How to create projects method with belongstomany relationship in user model
- How to upload image in laravel 8
- Laravel create multiple records in Pivot table
- Class 'App\Http\Controllers\User' not found
- Laravel onclick function not working
- How to add unique records in pivot columns of Laravel pivot table
- Method Illuminate\Database\Eloquent\Collection::lists does not exist
- How to add a key value pair to existing array in laravel
- How to pass query string to url in laravel
- Validation for multiple forms on same page in laravel
- Get last week data in Laravel
- Create records using relationship in laravel
- Get previous date data in laravel
- Undefined property: stdClass::$title
- How to pass data to multiple partial view files in laravel
- Laravel save object to database
- How to check records exist in loaded relationship in Laravel blade view
- Get Array of IDs from Eloquent Collection