Skip to main content

Black Friday 2025! Only until December 1st: coupon FRIDAY25 for 40% off Yearly/Lifetime membership!

Read more here
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.

Comments & Discussion

No comments yet…