theanadimukt/routes-dir-iterator

Iterate nested directories for segregated routes

1.1 2022-05-15 21:57 UTC

README

Latest Version on Packagist GitHub Tests Action Status GitHub Code Style Action Status Total Downloads

This package contains a RoutesDirIterator facade class that you can use to register segregate routes from nested directories at one place.

Installation

You can install the package via composer:

composer require theanadimukt/routes-dir-iterator

Usage

For example, routes for admin and guest has written in seperate files in nested directory structure for clean code.

routes
├── admin
│   ├── posts.php
│   ├── routes.php
│   └── settings
│       ├── permissions.php
│       └── roles.php
├── guest
│   └── routes.php
└── web.php

posts.php - Add relevent routes to file

use Illuminate\Support\Facades\Route;

Route::get('/posts', function () {
    return view('admin.posts.index');
});

web.php - Use of package's RoutesDirIterator facade class.

use TheAnadimukt\RoutesDirIterator\Facades\RoutesDirIterator;
use Illuminate\Support\Facades\Route;

Route::middleware('auth')
    ->prefix('admin')
    ->name('admin.')
    ->group(function () {
        RoutesDirIterator::read(__DIR__ . "/admin");
    });

Route::middleware('guest')
    ->group(function () {
        RoutesDirIterator::read(__DIR__ . "/guest");
    });

Under the hood package will do the necessary work to register all segreagated routed and make it publishable.

List all published routes in using command

php artisan route:list

Testing

composer test

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security Vulnerabilities

Please review our security policy on how to report security vulnerabilities.

Credits

License

The MIT License (MIT). Please see License File for more information.