A Laravel package that introduces a clean object based alternative to Laravel route files.

Overview

A Laravel package that introduces a clean object based alternative to Laravel route files.

Packagist Version Packagist PHP Version Support GitHub codecov

Laravel Route Registrars

This package introduces a clean object based way to define your routes in a Laravel application. A tutorial on the basic premise exists on Laravel news, written by @juststeveking.

Install

Install via composer.

$ composer require olliecodes/laravel-route-registrars

Fresh Laravel Installation

If you're installing this package on a fresh laravel installation, you'll want to run the following command before you do anything with your routes.

php artisan init:routing

This will overwrite the app/Providers/RouteServiceProvider.php file with one compatible with the route registrars, and create default route registrars to replace both routes/web.php and routes/api.php.

Existing Laravel Installation

If you have an existing application, it is recommended that you read through the Laravel News article that covers this approach, as you're going to have to manually refactor your route service provider and route files.

Requirements

This package requires the following;

  • PHP >= 8.0 (Including 8).
  • laravel/framework >= 9.0

Usage

To register new routes, you can either add their definitions to the map method of a RouteRegistrar, or create a new one.

Creating a new registrar

The following command will create a new registrar inside app/Http/Routes.

php artisan make:registrar {name}

The {name} can be any valid class name, or sub-namespace. For example, using Auth\\GuestRoutes will create app/Http/Routes/Auth/GuestRoutes.php.

There are several options available when creating a registrar.

--C|hasChildren

Create a route registrar that has the MapRouteRegistrars trait so that it can map child registrars.

--W|web

Create the route registrar in app/Http/Routes/Web, an option left in for those of you that are splitting the Web and API routes.

--A|API

Exactly the same as the above option, except it creates it in app/Http/Routes/Api,

Registering Registrars

Any class that wants to register registrars can use the following trait.

OllieCodes\Registrars\Concerns\MapsRouteRegistrars

Once doing so, there are three ways to register. All of them require an instance of the following class.

Illuminate\Contracts\Routing\Registrar

This interface is implemented by the Laravel Router class, so you can use that.

Register multiple

Call the following method with an instance of the laravel router, and an array of fully qualified class names for the registrars.

mapRouteRegistrars(Registrar $router, array $registrars)

Register one

Call the following method with an instance of the laravel router, and the fully qualified class name of the registrars.

mapRouteRegistrar(Registrar $router, string $registrar)

Register from paths

Call the following method with an instance of the laravel router, and an array of paths where the registrars are held.

This method will use the order that the files are returned, so please keep route order precedence in mind.

loadRouteRegistrars(Registrar $router, array $paths)
You might also like...
An easy way to desensitize your routes in your Laravel application

The package provides an easy way to desensitize your routes in your Laravel application. In short, Desensitize makes your routes case-insensitive, so you can access any of your routes whether they are lowercase, uppercase, or both.

route:menu gives you a beautiful route list which is friendly on smaller terminals and brings a few new features in.
route:menu gives you a beautiful route list which is friendly on smaller terminals and brings a few new features in.

Laravel Route Menu Your route:list, sir. route:menu gives you a beautiful route list which is friendly on smaller terminals and brings a few new featu

An article about alternative solution for convert object into a JSON Object for your api.

Do we really need a serializer for our JSON API? The last years I did build a lot of JSON APIs but personally was never happy about the magic of using

This WordPress Plugin introduces advanced citation capabilities to the WordPress Block Editor.
This WordPress Plugin introduces advanced citation capabilities to the WordPress Block Editor.

Citations for WordPress This WordPress plugin introduces practical citation functionality to the WordPress Block Editor, aiming to streamline the proc

Documentation on clean coding and demonstration of studied clean coding principals with PHP.

practice-php-clean-code Documentation on clean coding and demonstration of studied clean coding principals with PHP. The document contained in this re

A simple laravel package to handle multiple key based model route binding

Laravel Model UUID A simple package to handle the multiple key/column based route model binding for laravel package Installation Require the package u

Gretel is a Laravel package for adding route-based breadcrumbs to your application.
Gretel is a Laravel package for adding route-based breadcrumbs to your application.

Gretel Laravel breadcrumbs right out of a fairy tale. Gretel is a Laravel package for adding route-based breadcrumbs to your application. Defining Bre

Auto Route Generating (Auto-Discovery) Package for Laravel.

Laravel Auto Routes _ _____ _ /\ | | | __ \ | |

Calibre OPDS (and HTML) PHP Server : web-based light alternative to Calibre content server / Calibre2OPDS to serve ebooks (epub, mobi, pdf, ...)

COPS COPS stands for Calibre OPDS (and HTML) Php Server. See : COPS's home for more details. Don't forget to check the Wiki. Why ? In my opinion Calib

A server side alternative implementation of socket.io in PHP based on workerman.

phpsocket.io A server side alternative implementation of socket.io in PHP based on Workerman. Notice Only support socket.io v1.3.0 or greater. This pr

A simple PHP library to transfer data from a source (object or array) to an object.

SimplexMapper A simple PHP library to transfer data from a source (object or array) to an object. $dbData = [ 'username' = 'pfazzi', 'emailAd

Your alter ego object. Takes the best of object and array worlds.

Supporting Opensource formapro\values is an MIT-licensed open source project with its ongoing development made possible entirely by the support of com

Generate Laravel route URLs from JavaScript.
Generate Laravel route URLs from JavaScript.

Laroute Laravel has some pretty sweet helper functions for generating urls/links and its auto-json-magic makes it building APIs super easy. It's my go

Quickly identify controller methods with no route in your Laravel applications.
Quickly identify controller methods with no route in your Laravel applications.

Orphan Controller Quickly identify controller methods with no route in your Laravel applications. Installation You can install the package via Compose

#️⃣  Generate, Save, and Route Stripe-like Hash IDs for Laravel Eloquent Models
#️⃣ Generate, Save, and Route Stripe-like Hash IDs for Laravel Eloquent Models

Using this package you can generate, save and, route Stripe-like Hash Ids for your Eloquent Models. Hash Ids are short, unique, and non-sequential, an

Checks if a laravel route is vlaid
Checks if a laravel route is vlaid

Laravel Route Checker Checks if your Laravel routes has valid controllers Installation The package should be installed as a dev dependency, as there i

A Laravel REST API backend with React/Redux, hot module reloading in development and route-level code splitting

React Laravel Boilerplate This is the boilerplate that I personally use for getting projects off the ground quickly using my favourite stack of techno

Releases(v1.0.0)
Owner
Ollie Codes
Ollie Codes
Auto Route Generating (Auto-Discovery) Package for Laravel.

Laravel Auto Routes _ _____ _ /\ | | | __ \ | |

İzni Burak Demirtaş 201 Jan 1, 2023
Checks if a laravel route is vlaid

Laravel Route Checker Checks if your Laravel routes has valid controllers Installation The package should be installed as a dev dependency, as there i

Worksome 6 Dec 9, 2021
A lightweight and simple object oriented PHP Router

bramus/router A lightweight and simple object oriented PHP Router. Built by Bram(us) Van Damme (https://www.bram.us) and Contributors Features Support

Bramus! 935 Jan 1, 2023
Fast PSR-7 based routing and dispatch component including PSR-15 middleware, built on top of FastRoute.

Route This package is compliant with PSR-1, PSR-2, PSR-4, PSR-7, PSR-11 and PSR-15. If you notice compliance oversights, please send a patch via pull

The League of Extraordinary Packages 608 Dec 30, 2022
:tada: Release 2.0 is released! Very fast HTTP router for PHP 7.1+ (incl. PHP8 with attributes) based on PSR-7 and PSR-15 with support for annotations and OpenApi (Swagger)

HTTP router for PHP 7.1+ (incl. PHP 8 with attributes) based on PSR-7 and PSR-15 with support for annotations and OpenApi (Swagger) Installation compo

Sunrise // PHP 151 Jan 5, 2023
Convention based routing for PHP

Croute Convention based routing for PHP based on Symfony components. Croute is great because: You don't need to maintain a routing table Promotes cons

Michael O'Connell 12 Nov 9, 2021
PHPRouter is an easy-to-use, fast, and flexible PHP router package with express-style routing.

PHP-Router is a modern, fast, and adaptable composer package that provides express-style routing in PHP without a framework.

Ayodeji O. 4 Oct 20, 2022
A PHP Router Package

Router A PHP Router Package Basic Concepts A router package is a utility that, once all http requests are redirected to an entry point, can configure

null 0 Aug 26, 2022
PHP routing (like laravel) (not complete yet)

PHP Router (under construction) This repository contains routing classes that enables you to define your routes similar to laravel 8 routes. Features

Kareem M. Fouad 6 Jan 16, 2022
Manage redirects using database rules. Rules are intended to be very similar to Laravel default routes, so syntax is pretty easy to comprehend.

Laravel DB redirector Manage HTTP redirections in Laravel using database Manage redirects using database rules. Rules are intended to be very similar

Vladimir Ković 12 Jul 18, 2022