如何在另一个路线组内添加路线组.. Laravel 5

时间:2016-02-26 13:49:38

标签: laravel-5 routing

<paper-card style="width:100%;line-height:56px;font-size:16px;font-weight:400;">
  <paper-icon-button class="mybutton" id="mybutton" icon="hardware:keyboard-arrow-up" style="float:right;margin:8px;" >
  </paper-icon-button>
    <iron-icon icon="communication:forum"></iron-icon>
    <iron-collapse id="moreinfo" class="moreinfo" style="width:100%;">
      <paper-item>
        <iron-icon icon="info"></iron-icon>
        <paper-item-body two-line>
          <div>Primary text</div>
          <div secondary>Secondary text</div>
        </paper-item-body>
      </paper-item>
      <paper-item>Second item</paper-item>
      <paper-item>Third item</paper-item>
    </iron-collapse>
</paper-card>

我想在中间件路由中添加前缀组路由,我该如何实现呢?

2 个答案:

答案 0 :(得分:2)

您可以将路径组嵌套在彼此内部。只需将一个包裹在另一个的封闭中。

Route::group(['middleware' => 'cors'], function(Router $router){
    Route::group(
        [
          'prefix' => 'api/v1',
          'namespace' => 'Api'
        ], function () {
            Route::post('/auth/register', [
                'as' => 'auth.register',
                'uses' => 'AuthController@register'
             ]);

            Route::post('/auth/login', [
                'as' => 'auth.login',
                'uses' => 'AuthController@login'
            ]);
    });
});

答案 1 :(得分:0)

嘿,我解决了这个问题,

Route::group([

  'prefix' => 'api/v1',
  'namespace' => 'Api',
   'middleware'  =>'cors'

],
 function () {

    Route::post('/auth/register', [
    'as' => 'auth.register',
    'uses' => 'AuthController@register'


  ]);
  Route::post('/auth/login', [

    'as' => 'auth.login',
    'uses' => 'AuthController@login'

  ]);

});

但这里的问题是我收到了这个错误 XMLHttpRequest无法加载http://localhost:8000/api/v1/auth/login。 No&#39; Access-Control-Allow-Origin&#39;标头出现在请求的资源上。起源&#39; http://localhost:9000&#39;因此不允许访问。响应的HTTP状态代码为500。

我的chrome是否有任何问题,因为我听说有铬的插件插件。

谢谢:)