How to get route name on visit URL in laravel
How to get route name on visit URL in laravel
We will use programming in this lesson to attempt to solve the "How to get route name on visit URL in laravel".
You can get route name on visit URL in Laravel using request() method. You can use same code snippet in web.php, controller and view file to get the route name from URL In laravel-
Get route name using request() function on visit URL in laravel
//Syntax request()->route()->getName() //Demo code with output Route::get('/get-route-name', function(){ echo request()->route()->getName(); })->name('route.name');
Output:
route.name
This code snippet will help you to get the route name on visit a specific url in laravel. You have to just pass the name to route using name method while defining the route in web.php file.
Just copy/paste code in route\web.php file and visit /get-route-name url after running php artisan serve command to get the current route name.
-
Get route name using request() method on visit URL in laravel view
{{ request()->route()->getName() }}
Output:
home
Using this code snippet you can get the route name of current URL in laravel blade (view) file. You have to just specify the name for a route using name method on route definition in web.php.
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
- How to Get records between two dates in Laravel
- How to get specific columns using with method in laravel Eloquent relationship
- Class 'App\Providers\Auth' not found
- Send post data from controller to view
- Show old value while editing the form in Laravel
- Recursive function example code PHP Laravel
- Session Doesn't Work on Redirect
- Laravel pagination links with query string
- How to get selected categories on edit record with Select2
- Laravel URL validation not working
- Get ids in array from users table
- How to use or operator in laravel
- How to create project_user pivot table in laravel
- How to upload files to amazon s3 bucket using Laravel
- Laravel order by date not working
- How to prevent host header attack in Laravel
- How to check email is valid or not in Laravel
- How to display serial number in Laravel?
- Create record with unique slug in laravel
- SQLSTATE[23000]: Integrity constraint violation: 1022 Can't write; duplicate key in table
- 419 page expired error in Laravel
- How to add dynamic page title in Laravel view
- How to disable timestamps in laravel
- On delete set foreign id column value null using migration in laravel 8
- How to check if user has created any post or not in laravel