samedi 31 décembre 2016

Laravel: Best way to impement dynamic routing in routes.php based on environment variable?

My aim is to roll out a big re-theming / re-skinning (including new URL routing) for a Laravel v5 project without touching the existing business logic (as much as possible that is).

This is my current approach:

  1. I placed a APP_SKIN=v2 entry in my .env file

  2. My app\Http\routes.php file has been changed as follows:

    if (env('APP_SKIN') === "v2") {
    
        # Point to the v2 controllers
        Route::get('/', 'v2\GeneralController@home' );
        ... all other v2 controllers here ...
    
    } else {
    
        # Point to the original controllers
        Route::get('/', 'GeneralController@home' );
        ... all other controllers
    
    }
    
    
  3. All v2 controllers have been placed in app/Http/Controllers/v2 and namespaced accordingly

  4. All v2 blade templates have been placed in resources/views/v2
  5. the rest of the business logic remains exactly the same and shared between the "skins".

My question: Is there a "better" way to achieve the above?. Please note that the idea here is to affect as few files as possible when doing the migration, as well as ensure that the admin can simply change an environment variable and "roll back" to the previous skin if there are problems.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire