Inside this article we will see the concept i.e Laravel 9 How To Get All Application Routes Tutorial. Article contains the classified information about how to get all routes in laravel.
If you are looking for a solution i.e how to list all application routes in laravel then this article will help you a lot for this. Tutorial is super easy to understand and implement it in your code as well.
The route is a way of creating a request URL for your application. These URLs do not have to map to specific files on a website, and are both human readable and SEO friendly.
Read More: Laravel 9 Redirection with Form Inputs Example Tutorial
Let’s get started.
Laravel Installation
Open terminal and run this command to create a laravel project.
composer create-project laravel/laravel myblog
It will create a project folder with name myblog inside your local system.
To start the development server of laravel –
php artisan serve
URL: http://127.0.0.1:8000
Assuming laravel already installed inside your system.
Create Controller
Back to project terminal and run this command to create a controller file.
$ php artisan make:controller SiteController
Above command will create a file i.e SiteController.php inside /app/Http/Controllers folder.
<?php namespace App\Http\Controllers; use Illuminate\Http\Request; use Illuminate\Support\Facades\Route; class SiteController extends Controller { /** * Write code on Method * * @return response() */ public function index() { $routes = Route::getRoutes(); return view('routesList', compact('routes')); } }
Create Blade Template File
Create a file routesList.blade.php inside /resources/views folder.
Read More: CodeIgniter 4 Redirection with Form Inputs Example Tutorial
Open view file and write this code into it.
<!DOCTYPE html> <html> <head> <title>Laravel 9 How To Get All Application Routes Tutorial</title> <link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/5.0.1/css/bootstrap.min.css" rel="stylesheet"> </head> <body> <div class="container"> <br> <h3 style="text-align: center;">Laravel 9 How To Get All Application Routes Tutorial</h3> <br> <table class="table table-bordered data-table"> <thead> <tr> <th>Method</th> <th>URI</th> <th>Name</th> <th>Action</th> </tr> </thead> <tbody> @foreach ($routes as $route) <tr> <td>{{ $route->methods()[0] }}</td> <td>{{ $route->uri() }}</td> <td>{{ $route->getName() }}</td> <td>{{ $route->getActionName() }}</td> </tr> @endforeach </tbody> </table> </div> </body> </html>
Create Route
Open web.php file from /routes folder. Add this route into it.
//... use App\Http\Controllers\SiteController; Route::get('get-all-routes', [SiteController::class, 'index']); //...
Application Testing
Run this command into project terminal to start development server,
php artisan serve
URL: http://127.0.0.1:8000/get-all-routes
We hope this article helped you to learn Laravel 9 How To Get All Application Routes Tutorial in a very detailed way.
Read More: CodeIgniter 4 How To Redirect with Flashdata Example Tutorial
Online Web Tutor invites you to try Skillshike! Learn CakePHP, Laravel, CodeIgniter, Node Js, MySQL, Authentication, RESTful Web Services, etc into a depth level. Master the Coding Skills to Become an Expert in PHP Web Development. So, Search your favourite course and enroll now.
If you liked this article, then please subscribe to our YouTube Channel for PHP & it’s framework, WordPress, Node Js video tutorials. You can also find us on Twitter and Facebook.