2017-06-09 167 views
2

web.php看起来像子域的路由名称

Route::group(
    [ 
     'domain'  => '{tenant}.' . config('app.url'), 
    ], 
    function() { 
     $this->get('/', '[email protected]')->name('home'); 
    } 
); 

HomeController看起来像

/** 
* Show the application dashboard. 
* 
* @param $tenant 
* @return \Illuminate\Http\Response 
*/ 
public function index($tenant) 
{ 
    return view('home', compact('tenant')); 
} 

app.blade.php文件看起来像

<a href="{{ route('home', ['tenant', $tenant]) }}">home</a> 

使用我们在子域路由在我们的时候每次都会传递通配符{tenant} SE route()否则它会弹出这个错误

(3/3) ErrorException 
Missing required parameters for [Route: home] [URI: home]. 

这是多余的遍布controller以及blade文件。有没有什么解决方案可以默认绑定{wildcard}

回答

1

创建一个使用现有的route()函数的新函数。

例子:

function mdroute ($routeName, $routeData = []) 
{ 
    $tenant = request()->tenant; 

    $routeData['tenant'] => $tenant; 

    return route($routeName, $routeData); 
} 
+0

我应该在哪里定义呢? –

+0

将此功能添加到您使用作曲者加载的文件中。作曲家的例子:' ''autoload“:{”files“:[”path/to/file“]}'。 –

+0

你的意思是像辅助函数一样使用这种方法吗? –