tar*_*nik 0 laravel laravel-blade
我想检查我的 URL 中的数据是否有任何参数?我以前用过这个条件
@if(app('request')->input('type') || app('request')->input('type-2') || app('request')->input('type-3') || ... many more....)
<-- code here -->
@endif
Run Code Online (Sandbox Code Playgroud)
现在它的参数太多了。有没有最短的方法来检查是否有任何参数?喜欢app('request')->has('input')这种最短路线吗?请帮忙注意:laravel 版本 6.19
Request::hasAny()应该可以解决你的问题:
@if (request()->hasAny('type', 'type-2', 'type-3'))
Run Code Online (Sandbox Code Playgroud)
它检查当前请求中是否存在任何给定的输入项键。您还可以用来Request::has检查是否所有给定的输入项键都存在。
要安全地检查当前请求中是否有任何输入,请使用Request::except():
@if (!empty(request()->except('_token', '_method')))
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1273 次 |
| 最近记录: |