laravel - 有没有办法删除 Laravel URL 中的 %20 ?
问题描述
这是我到目前为止所拥有的。
在刀片模板中
<a href='{{ url("/businessprofile/$business->id/$business->name") }}'>
并在 web.php
Route::get('/businessprofile/{id}/{name}', 'BusinessController@show')
表明
localhost:8000/businessprofile/User%20Info
有没有办法删除 %20 而只显示 localhost:8000/businessprofile/UserInfo ?
解决方案
该Str::slug
方法从给定的字符串生成一个 URL 友好的“slug”:
{{ url("/businessprofile/$business->id"."/" . Str::slug($business->name)) }}'>}}
或者,
{{ url("/businessprofile/$business->id"."/" . str_slug($business->name)) }}
如果上述方法不起作用,则将您的路线和视图更改为:
路线:
Route::get('/businessprofile/{id}/{name}', 'BusinessController@show')->name('businessprofile.show');
观点:
{{ route('businessprofile.show', ['id' => $business->id, 'name' => str_slug($business->name) ]) }}
在此处查看官方文档
推荐阅读
- python - 仅打印对象的一部分
- c - 我们是否通过复制一个悬空指针来获得一个悬空指针?
- visual-studio - 什么是致命错误 C1090:PDB API 调用失败,错误代码“3”:vc142.pdb?
- python-3.x - Python Pivot Rows into Columns Group by Max
- powershell - 可以记录已扫描文件并在下次运行时忽略它们的 Powershell 脚本?
- jquery - Jquery Bootgrid 最初加载数据然后空白
- python - 如何为 Ansible 剧本选择 Python 解释器?
- cakephp - 树枝模板文件中的 Bake.columnData 是什么
- javascript - 使用 javaScript 将输入信息发送到另一个 html 页面
- java - 在 Freemarker 文件中链接 CSS 文件