Routing allows the user to route application requests to its appropriate controller. Laravel has an inbuilt API which is really helpful and time-saving. Hence, it is important for newcomers to know and extend their knowledge about routing.

Users can learn about routing technique basics from here. Please go through the link to get more familiar with routing.

Here are a few tricks that can help you to use routing in Laravel:

Using Custom Namespace

Users can define namespace for a group of routes using fluent routing API.

Route::namespace('Admin')->group(function () {
    // Controllers Within The "App\Http\Controllers\Admin" Namespace
});

Run the command given below to create controller in App\Http\Controllers\Admin:

php artisan make:controller -r Admin/UsersController

After running the command, routes/web.php will look like this:

Route::namespace('Admin')
    ->prefix('admin')
    ->group(function () {
        Route::resource('users', 'UsersController');
    });

Debug Routes

To find or debug all defined routes, users can run php artisan route:list . Basically what this command does is that it helps to see the name of all routes and attached middleware to the route.

php artisan route:list
+--------+----------+----------+------+---------+--------------+
| Domain | Method   | URI      | Name | Action  | Middleware   |
+--------+----------+----------+------+---------+--------------+
|        | GET|HEAD | /        |      | Closure | web          |
|        | GET|HEAD | api/user |      | Closure | api,auth:api |
+--------+----------+----------+------+---------+--------------+

#tutorials #routing #laravel

How to Improve Routing In Laravel - LaravelProject
1.20 GEEK