New

Just launched: Vueblocks, a brand-new search engine for Vue packages! Explore Vueblocks →

elemenx/lumen-advanced-route

Add Support For Nested Group && Resource.
9,862 2
Install
composer require elemenx/lumen-advanced-route
Latest Version:0.2.0
PHP:>=7.3
License:MIT
Last Updated:Jan 27, 2021
Links: GitHub  ·  Packagist
Maintainer: branchzero

Note

inspired by fremail/lumen-nested-route-groups, adding support for lumen resource route.

Changelog

  • v.0.1.1 Remove Useless Code.
  • v.0.1.0 Add Support For Lumen 5.5 && Resource.

How to install (steps)

1. Install using Composer

composer require "elemenx/lumen-advanced-route:~0.1"

2. Required changes in bootstrap/app.php

Change initialization of Lumen Application class to initialization of Lumen Nested Route Groups Application class in bootstrap/app.php.

Before:

$app = new Laravel\Lumen\Application(
    realpath(__DIR__.'/../')
);

After:

$app = new ElemenX\AdvancedRoute\Application(
    realpath(__DIR__.'/../')
);

Any() and Match() and resource() methods

Do you like any() and match() methods on Laravel? I love them! That's why I added supporting them on Lumen. The syntax is the same as for Laravel:

$app->match($methods, $uri, $action);

Where $methods - an array of methods. Example: ['get', 'post', 'delete']. $uri and $action are the same as on other methods

$app->any($uri, $action);

Here are $uri and $method are the same as on other methods like $app->get(...) etc.

Example of using this lib

This is an example of routes/web.php

$app->group(['middleware' => 'auth'], function () use ($app) {

    $app->get('test', function () {
        echo "Hello world!";
    });

    $app->resource('user', 'UserController', ['only' => ['show', 'store', 'destroy']]);

    /**
     * only admins
     */
    $app->group(['middleware' => 'admin'], function () use ($app) {

        $app->group(['prefix' => 'admin'], function () use ($app) {
            $app->get('/', 'AdminController@index');
        });

    });
    
    /**
     * $app->any and $app->match available from v1.1.0
     */
    $app->any('/', function () use ($app) {
        echo "Hey! I don't care it's POST, GET, PATCH or another method. I'll answer on any of them :)";
    });
    
    $app->match(['PATCH', 'PUT', 'DELETE'], '/old/', function () use ($app) {
        echo "This is an old part of our site without supporting REST. Please use only GET and POST here.";
    });

});

Related Packages

fremail/lumen-nested-route-groups

Extends a lumen application for using nested route groups. In addition to the gr...

11,054 15
sayeed/lumen-route-list

List all registered routes

1,028 4
chhw/route-list

This package can list all routes just as Laravel do.

7 2
five-say/laravel-route-group

Object-oriented route group.use like this: $route->get(...)->as(...)->uses(...)-...

671 4
syntags/lumen-route-binder

This package enables you to use laravel like Route Model Binding in Lumen

10 0

Version History

Version Released PHP License
0.2.0 >=7.3 MIT
0.1.8 >=7.2 MIT
0.1.7 >=7.2 MIT
0.1.4 >=7.0 MIT
0.1.2 >=7.0 MIT