无法在默认 routes/web.php 之外的视图中使用 routes('name') 函数

Cannot use routes('name') function in view outside of default routes/web.php

我有一个组使用 WEB 中间件(默认),但有自己的 routes/org.php 文件;

来自RouteServiceProvider.php:

protected function mapWebRoutes()
{

    // Match my own domain FIRST
    Route::group(['domain' => 'a.example','www.a.example', 'admin.a.example'], function()
    {
        // Original Web Route
        Route::middleware('web')
             ->namespace($this->namespace)
             ->group(base_path('routes/web.php'));
    });



    // Match any other domains or subdomains
    Route::group(['domain' => '{domain}'], function()
    {
        // Org middleware
        Route::middleware('web')
            ->namespace($this->namespace)
            ->group(base_path('routes/org.php'));
    });

}

```

routes/org.php 我有 Route::get('/test', 'OrgTestCtrlr@test')->name('test');

相关信息:

OrgTestCtrlr extends OrgBaseCtrlr

.. OrgBaseCtrlr extends Controller(默认 laravel 控制器)

(所以基本上 OrgTest 扩展了 OrgBase 扩展了 Controller)

我的职能 public function test() { return view('org.test'); }

../views/org/test.blade.php

中调用 blade 文件

在这个文件中,我尝试有一个 {{ route('test') }} 参考

我收到这个错误

"Missing required parameters for [Route: test] [URI: test]."

*我已经移动了命名空间,尝试不多次扩展控制器等等,我只是在追尾。请指教

您也需要传递域:

{{ route('test', ['domain' => 'some_domain']) }}

另外,将方法改为:

public function test($domain) {
    return view('org.test');
}