如何根据Laravel刀片使用的路径“类别”包含文件?我基本上试图在我的视图模板的子导航部分中执行此操作:
应用程序/视图/布局/ default.blade.php
@if (Route::resource() == 'tasks')
@include('navs.task')
@elseif (Route::resource() == 'projs')
@include('navs.proj')
@elseif (Route::resource() == 'miscs')
@include('navs.misc')
@else
@include('navs.info')
@endif
但是会抛出错误“未定义的类常量'资源'”
答案 0 :(得分:0)
你在Route :: currentRouteName()之后。
@if (Route::currentRouteName() == 'tasks')
@include('navs.task')
@elseif (Route::currentRouteName() == 'proj')
@include('navs.proj')
@elseif (Route::currentRouteName() == 'misc')
@include('navs.misc')
@else
@include('navs.info')
@endif
答案 1 :(得分:0)
很晚,但我认为使用Request :: is是一种更简单的方法。
@if (Route::is('tasks'))
@include('navs.task')
@elseif (Route::is('projs'))
@include('nav.proj')
@elseif (Route::is('miscs'))
@include('nav.misc')
@else
@include('nav.info')
@endif
此外,如果还有其他情况,请使用Switch案例。
答案 2 :(得分:-1)
@if (Route::current()->getUri() == 'tasks')
@include('nav.task')
@elseif (Route::current()->getUri() == 'projs')
@include('nav.proj')
@elseif (Route::current()->getUri() == 'miscs')
@include('nav.misc')
@else
@include('nav.info')
@endif