2016-11-26 19 views
3
@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') 

這裏是我的main.blade.php文件中的一個例子,現在我正在做的是我試圖使用2個不同的導航欄 - 我知道有一個更好的方法來做到這一點,但我仍然可以抓不住它!Laravel Request :: is() - 有沒有更好的方法?

我不認爲重複Request ::的好編碼標準是一遍又一遍。我是新手:(我錯過了什麼那邊

回答

8

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}')) 
+1

感謝您快速回復,確實很有幫助。 –

相關問題