首页 > 解决方案 > 网址生成 Laravel

问题描述

我有 url 格式/catalog/{countryName}/。需要填写网址

$country = 'russia'
(\route('country',['countryName' => $country])); // http://localhost/catalog/russia

结果 = http://localhost/catalog/russia

但我需要 result = /catalog/russiaformaty 唯一路径使用标准方法 Laravel。

标签: phplaravel

解决方案


像这样调用你的路线:

route('pages.countryCatalog', $country)

在您的路线中,尝试输入 {country}。

例如:

Route::get('/catalog/{country?}', 'Your Controller Name here@Your Method')->name('pages.countryCatalog');

将页面命名为您想要的名称,只需确保它们匹配,以便路线知道要去哪条路线!

注意:您不需要 {} 中的问号,它表示它是一个可选参数。

希望有帮助!


推荐阅读