php - 网址生成 Laravel
问题描述
我有 url 格式/catalog/{countryName}/
。需要填写网址
$country = 'russia'
(\route('country',['countryName' => $country])); // http://localhost/catalog/russia
结果 = http://localhost/catalog/russia
。
但我需要 result = /catalog/russia
formaty 唯一路径使用标准方法 Laravel。
解决方案
像这样调用你的路线:
route('pages.countryCatalog', $country)
在您的路线中,尝试输入 {country}。
例如:
Route::get('/catalog/{country?}', 'Your Controller Name here@Your Method')->name('pages.countryCatalog');
将页面命名为您想要的名称,只需确保它们匹配,以便路线知道要去哪条路线!
注意:您不需要 {} 中的问号,它表示它是一个可选参数。
希望有帮助!
推荐阅读
- python - 使用 *args 时出现“方法与超类型不兼容”:Any
- automation - 如何使用机器人框架处理适合移动自动化中多个页面的列表?
- typescript - 如何用“记录”替换“对象”
`? - angular - Angular 项目部署不使用 #useHash 和 HashLocationStrategy
- terminology - 用例实例和场景
- delphi - TWSDLHTMLPublish 生成错误的 wsdl?
- php - 迭代时更改一个雄辩的对象值
- ios - Swift/Objective-C Crash: Swapped class initializers while debugging
- java - 无法通过反射访问所有视图字段
- python - 将球面坐标转换为笛卡尔坐标然后再转换回笛卡尔坐标并不能提供所需的输出