问题
I am trying to set active classes on active menus. In the past I was using Request::is() function for this, but in the new version of laravel it says "Class 'Request' not found."
回答1:
As you are using blade
you can use request helper method. Try like this
request()->is('your_url');
回答2:
do not put / before the route. it should be like
@if(Request::is('index'))
@include('include.showcase')
@endif
回答3:
please check in your code
you add this line as namespace or not
use Illuminate\Http\Request;
and you can also pass one varriable with view from controller side and check on blade template if you get that data then you can use active class for that menu. like this
in controller what i had used in my project
$data['page-tab'] = 'adduser';
return view('user.add_user',compact('data'));
and in blade file i had checked this like this in sidebar section
<li class="{{ isset($data['page-tab']) && $data['page-tab'] == 'adduser' ? 'active' : '' }}"><a href="{{ route('adduser') }}"><i class="fa fa-file-text-o"></i>Manage Member</a></li>
hope this works for you.
来源:https://stackoverflow.com/questions/47974432/requestis-not-working-on-laravel-5-5-in-blade