Skip to main content
Tutorial Free

Laravel Router - a package to organize your routes

April 13, 2016
2 min read

One of the most common questions in Laravel world is how to organize the routes file, especially for bigger projects. Of course, you can have groups, prefixes and similar things, but today I want to present to you a package by Sebastiaan Luca - called Laravel Router.

Basically, this package allows you to group your routes into different files. As the author himself says:
"For instance admin, public, and user routes are separated into different classes instead of one long routes.php file"

You can find a detailed documentation on package GitHub page in Readme section, I will just summarize the main point - as a result, you create your "Routers" in app/Http/Routers folder, and here's how one router file looks like:

namespace App\Http\Routers;

use SebastiaanLuca\Router\Routers\BaseRouter;
use SebastiaanLuca\Router\Routers\RouterInterface;

class PublicRouter extends BaseRouter implements RouterInterface
{

    /**
     * Map the routes.
     */
    public function map()
    {
        $this->router->get('/', function () {
            return 'Congratulations!';
        });
    }

}

Then you add all your "routers" into application's Kernel class and that's it. Within $this->router you can use all the same functions as in a common routes.php file.

What do you think? Useful package? If not, how do you structure your routes in bigger projects?
Link once again: Laravel Router

Enjoyed This Tutorial?

Get access to all premium tutorials, video and text courses, and exclusive Laravel resources. Join our community of 10,000+ developers.

Recent Courses

Filament 4 From Scratch

28 lessons
2 h 25 min

Claude Code for Laravel Projects: Crash Course

8 lessons
48 min

Laravel HTTP Client and 3rd-Party APIs

7 lessons
50 min

Comments & Discussion

No comments yet…

We'd Love Your Feedback

Tell us what you like or what we can improve

Feel free to share anything you like or dislike about this page or the platform in general.