Laravel blade @if 语句条件检查路由名称
Laravel blade @if statement conditional to check route names
有没有办法用blade查看当前页面的路由名称?我有一个 blade 布局模板,需要通过当前 uri 更改它的 <body>
属性。请注意,我需要通过 blade 来完成此操作,而不是 js。
这是一个示例片段,说明了我想要做什么:
@if (URL::current() == {{ route('admin.index') }}) //not valid syntax
<body class="dashboard" id="top">
@else
<body class="not-dashboard" id="not-top">
@endif
你可以试试routeIs()
助手
@if (request()->routeIs('admin.index'))
<body class="dashboard" id="top">
@else
<body class="not-dashboard" id="not-top">
@endif
你的代码有语法错误,修复方法是
@if (URL::current() == route('admin.index')) // remove those curly braces
<body class="dashboard" id="top">
@else
<body class="not-dashboard" id="not-top">
@endif
有没有办法用blade查看当前页面的路由名称?我有一个 blade 布局模板,需要通过当前 uri 更改它的 <body>
属性。请注意,我需要通过 blade 来完成此操作,而不是 js。
这是一个示例片段,说明了我想要做什么:
@if (URL::current() == {{ route('admin.index') }}) //not valid syntax
<body class="dashboard" id="top">
@else
<body class="not-dashboard" id="not-top">
@endif
你可以试试routeIs()
助手
@if (request()->routeIs('admin.index'))
<body class="dashboard" id="top">
@else
<body class="not-dashboard" id="not-top">
@endif
你的代码有语法错误,修复方法是
@if (URL::current() == route('admin.index')) // remove those curly braces
<body class="dashboard" id="top">
@else
<body class="not-dashboard" id="not-top">
@endif