@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?
Laravel's Illuminate\Http\Request class provides an object-oriented way to interact with the current HTTP request being handled by your application as well as retrieve the input, cookies, and files that were submitted with the request.
Or just use request()->isMethod('post') anywhere cause the function request() is registered globally in Laravel. Can be checked by request()->method === 'PUT' as well.
The “path” method is used to retrieve the requested URI. The is method is used to retrieve the requested URI which matches the particular pattern specified in the argument of the method. To get the full URL, we can use the url method.
-> and => are both operators. The difference is that => is the assign operator that is used while creating an array. For example: array(key => value, key2 => value2) And -> is the access operator. It accesses an object's value.
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}'))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With