Laravel:如何使用尾部斜杠创建路由路由返回URL?

tba*_*ack 8 php laravel laravel-5

如何使Laravel 5.3创建带有斜杠的路径URL?

该路线定义为

 Route::get('/home/', ['as' => 'home', 'uses' => 'HomeController@index']);
Run Code Online (Sandbox Code Playgroud)

然后我在视图中使用路径助手函数创建url:

{{ route('home') }}
Run Code Online (Sandbox Code Playgroud)

这创造了http://localhost:8000/home而不是http://localhost:8000/home/.

这个问题与Laravel非常相似- 在路线中附加一个尾随斜线,但这个问题也没有答案,在我看来,我的描述更短.

编辑:文档中的两种可能的命名方法没有区别:

Route::get('/home/', ['as' => 'home', 'uses' => 'HomeController@index']);
Route::get('/home/', 'HomeController@index')->name('home');
Run Code Online (Sandbox Code Playgroud)

San*_*yen 0

因为 Laravel 会删除 URL 末尾的斜杠,所以你只需使用{{ route('home') }}/.

参考: https: //github.com/laravel/framework/blob/5.3/src/Illuminate/Routing/UrlGenerator.php#L308-L345