
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 decrypt laravel password
- How to check data inserted or deleted in pivot after toggle method
- How to check column value of a record is null or not in laravel
- Delete records with relationship in laravel
- SQLSTATE[42000]: Syntax error or access violation: 1055
- Laravel 9 pagination with search filter
- Syntax error or access violation: 1072 Key column 'role_id' doesn't exist in table (SQL: alter table `users` add constraint `users_role_id_foreign` foreign key (`role_id`) references `roles` (`id`))
- Class "App\Http\Controllers\Auth\Verified" not found
- First and last item of the array using foreach iteration in laravel blade
- Trying to get property 'title' of non-object
- Route group with URI prefix using middleware and route name prefixes
- How to create belongstomany relation using custom name on custom pivot table
- Route [password.request] not defined
- Update last created record in Laravel
- Laravel append URI in route
- Redirect from www to non www in laravel using htaccess
- Ajax POST request in laravel
- In order to use the Auth::routes() method, please install the laravel/ui package
- How to send email in laravel
- Cannot end a section without first starting one
- If condition in Laravel 9
- How to create laravel project using composer
- How to upload image in laravel 8
- How to pass data to partial view file in laravel
- Generate random string lowercase in Laravel