Laravel 5 Global Routing Package

Łukasz Piotrowski Comments 0

    Hi!

    Laravel 5 Global Routing gives You possibility making own controllers and access to them via URL.
    Similar feature was released on CakePHP.


    Installation

    Add dependency to composer.json:

    “require": {
        “pyton/global-routing": “dev-master"
    }

    or run
    composer require pyton/global-routing

    To config/app.php file as last string add:

    ‘providers' => [    
        // …
    
        Pyton\GlobalRouting\GlobalRoutingServiceProvider::class,
    ],

    It's so important, because this ServiceProvide registers global route which could override some other entries.

    Usage

    We can access to global route:

    +--------+--------------------------------+----------------------------------+
    | Domain | Method                         | URI                              |
    +--------+--------------------------------+----------------------------------+
    |        | GET|HEAD|POST|PUT|PATCH|DELETE | {controller}/{action?}/{params?} |
    +--------+--------------------------------+----------------------------------+

    URL http://domain.pl/home/show/1 will bee mapped to:

    <?php
    
    namespace App\Http\Controllers;
    
    class HomeController extends Controller
    {
        public function showAction($id)
        {
            
        }
    }

    URL -> Controller Conversion Rules

    On Converting URL to Controller/Method there are few Rules:
    {controller} – home -> HomeController (ucfirst + sufix “Controller")
    {action} – show -> showAction (lowercase + sufix “Action")

    Params are separated by /. Params are mapped in the order of in URL.
    Bind param are not override and pass full Bind object ex.::

    public function showAction($id, Request $reques, $id2, $id3)
    {
    }

    Request $request will bind properly Object.

    Summary

    This is the first release and can have some bugs.
    Post all Your comments and suggestions.

    GitHub: https://github.com/Pyton/GlobalRouting

    Other posts

    Top