首页 > 解决方案 > 在路由函数中读取刀片变量

问题描述

我在 Laravel 中有一个系统,当我在视图中构建带有链接的模板时,我需要像这样动态插入一个路由:

<ul class="breadcrumbs pull-left">
    <li><a href="{{route('home')}}">Home</a></li>
    <li><a href="{{route('$route.index')}}">{{$title}}</a></li>
    <li><span>{{$activeList}}</span></li>
</ul>

如何在路由函数中读取刀片变量?

这不起作用:

{{route('$route.index')}}

错误:“未定义路由 [$active.index]。(查看:C:\xampp\htdocs\systemass\resources\views\templates\srtdash\inc\pagearea.blade.php)(查看:C:\xampp\htdocs \systemass\resources\views\templates\srtdash\inc\pagearea.blade.php)(查看:C:\xampp\htdocs\systemass\resources\views\templates\srtdash\inc\pagearea.blade.php

标签: phplaravelrouteslaravel-bladelaravel-5.8

解决方案


只需使用变量内容

<ul class="breadcrumbs pull-left">
    <li><a href="{{route('home')}}">Home</a></li>
    <li><a href="{{route($active.'.index')}}">{{$title}}</a></li>
    <li><span>{{$activeList}}</span></li>
</ul>

推荐阅读