Black Friday: coupon FRIDAY24 for 40% off Yearly/Lifetime membership! Read more here

Laravel Router - a package to organize your routes

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

No comments or questions yet...

Like our articles?

Become a Premium Member for $129/year or $29/month
What else you will get:
  • 67 courses (1172 lessons, total 43 h 18 min)
  • 90 long-form tutorials (one new every week)
  • access to project repositories
  • access to private Discord

Recent New Courses