Laravel dingo api group由多个域组成

时间:2017-12-07 13:23:14

标签: laravel dingo-api

是否可以将dingo api路由分组到多个域?例如

$api->group(['domain' => ['something.com', 'anotherexample.com]], function ($api) {

  // My routes

});

1 个答案:

答案 0 :(得分:-2)

您不必重复代码。

$callback = function() {};

Route::group(['domain' => 'foo.bar.dev'], $callback);
Route::group(['domain' => 'foo.bar'], $callback);

但我们还有一个微观解决方案

Route::macro("domain", function(array $domains, \Closure $definition) {
    foreach ($domains as $domain) {
        Route::group(['domain' => $domain], $definition);
    }
});
Route::domain(['foo.bar.dev', 'foo.bar'], function($route) {
    // Do stuff
});