Laravel Request::is() - is there a better way?
Asked Answered
A

2

18
@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

Above is an example in my main.blade.php file; I am trying to use 2 different navigation bars - I know there is a better way to do this but I still can't get the grasp of it!

I don't think it is good coding standards to repeat Request::is over and over again. I am a newbie :( what did I miss over there?

Arrhythmia answered 26/11, 2016 at 17:14 Comment(0)
S
40

is() method iterates over arguments:

foreach (func_get_args() as $pattern) {
    if (Str::is($pattern, $this->decodedPath())) {
        return true;
    }
}

So, something like this should work for you:

@if(Request::is('login', 'tags', 'categories', 'posts', 'tags/..', 'categories/..', 'posts/..', 'posts/{$post->id}'))
Scratchboard answered 26/11, 2016 at 17:32 Comment(1)
Thank you for your fast reply. Indeed this was very helpful.Arrhythmia
F
1

For User Add :- Request::is('user/add');

User Edit :- Request::is('user//edit'); Request::is('user/edit/');

Fenelia answered 30/3, 2020 at 13:42 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.