@if(Request::is('login') OR Request::is('tags') OR Request::is('categories') OR Request::is('posts') OR Request::is('tags/..') OR Request::is('categories/..') OR Request::is('posts/..') OR Request::is("posts/{$post->id}"))
@include('partials._navAdmin')
@else
@include('partials._nav')
@endif
以上是我的 main.blade.php
文件中的示例;我正在尝试使用 2 个不同的导航栏 - 我知道有更好的方法可以做到这一点,但我仍然无法掌握它!
我不认为一遍又一遍地重复Request::is
是好的编码标准。我是新手 :( 我错过了什么?
最佳答案
is()
方法遍历参数:
foreach (func_get_args() as $pattern) {
if (Str::is($pattern, $this->decodedPath())) {
return true;
}
}
所以,像这样的东西应该适合你:
@if(Request::is('login', 'tags', 'categories', 'posts', 'tags/..', 'categories/..', 'posts/..', 'posts/{$post->id}'))
关于php - Laravel Request::is() - 有更好的方法吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40820907/