“Request::is()” not working on laravel 5.5, in blade

天大地大妈咪最大 提交于 2020-08-08 06:23:09

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!