【发布时间】:2021-02-08 03:50:08
【问题描述】:
由于名誉问题,我无法对this other question发表评论,我再次询问。
就像OP发布的那样,Laravel的web.php文件中的路由如下:
$loginRoutes = function () {
Route::get('/', 'HomeController@index')->name('home');
};
Route::domain('domain1.com')->group($loginRoutes);
Route::domain('domain2.com')->group($loginRoutes);
Route::domain('localhost')->group($loginRoutes);
在 Blade 中调用命名路由时,例如使用 route('home') 时,上述代码最后一行中的域会添加到链接之前。
因此,如果我们在 domain1.com 上,并且刀片中的链接引用 route('home'),则 URL 将在前面添加 http://localhost 作为域。
如果不检查和硬编码网址,如何避免这种情况?
更新我已经破解了两种方法(发布为其他可能发生在这里的人的答案),但我希望有人可以提供一些清晰的更好的方法来处理这个问题。
【问题讨论】: