Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
352 views
in Technique[技术] by (71.8m points)

php - multiple route file instead of one main route file in laravel 5

I am a novice in web developing with Laravel 5. I installed asGgardCMS and After seeing asgardCms codes, I found that there is nothing codes in app/Http/route.php file and required codes for routing be placed in Modules codes. For example required code for routing menu manager module be placed in Modules/Media/apiRoutes.php and Modules/Media/backendRoutes.php files. May help me and tell me how I can manage my routes like that?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
  1. create 2 route files routes.web.php and routes.api.php.

  2. edit the RouteServiceProvider.php file to look like the example below:


<?php

namespace AppProviders;

use IlluminateFoundationSupportProvidersRouteServiceProvider as ServiceProvider;
use IlluminateRoutingRouter;

class RouteServiceProvider extends ServiceProvider
{

    /**
     * This namespace is applied to the controller routes in your routes file.
     *
     * In addition, it is set as the URL generator's root namespace.
     *
     * @var string
     */
    protected $webNamespace = 'AppHttpControllersWeb';

    protected $apiNamespace = 'AppHttpControllersApi';

    /**
     * Define your route model bindings, pattern filters, etc.
     *
     * @param  IlluminateRoutingRouter $router
     *
     * @return void
     */
    public function boot(Router $router)
    {
        //

        parent::boot($router);
    }

    /**
     * Define the routes for the application.
     *
     * @param  IlluminateRoutingRouter $router
     *
     * @return void
     */
    public function map(Router $router)
    {

        /*
        |--------------------------------------------------------------------------
        | Web Router 
        |--------------------------------------------------------------------------
        */

        $router->group(['namespace' => $this->webNamespace], function ($router) {
            require app_path('Http/routes.web.php');
        });

        /*
        |--------------------------------------------------------------------------
        | Api Router 
        |--------------------------------------------------------------------------
        */

        $router->group(['namespace' => $this->apiNamespace], function ($router) {
            require app_path('Http/routes.api.php');
        });

    }
}

Note: you can add as many route files as you want...


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...