【发布时间】:2021-08-03 17:14:09
【问题描述】:
在我的 Laravel (7.x) 应用程序中。我正在尝试为链接创建一个组件:
组件:
<a class="links" href="{{ $route }}" title="{{ $title ?? null }}">
@isset($icon)
<i class="{{ $icon }}"></i>
@endisset
@isset($caption)
<span>{{ $caption }}</span>
@endisset
</a>
<x-link icon="{{ $icon }}" route="{{ route("admin.{$route}.create") }}" />
OR
<x-link icon="{{ $icon }}" route="{{ route("admin." . $route. ".create") }}" />
OR
<x-link icon="{{ $icon }}" route="{!! route("admin.{$route}.create") !!}" />
OR
<x-link icon="{{ $icon }}" route="{!! route("admin." . $route. ".create") !!}" />
遇到这个问题:
syntax error, unexpected token "endif", expecting end of file (View: \path)
但是,如果我这样做,那么它会起作用:
$url = route("admin.{$route}.create");
...
<x-link icon="{{ $icon }}" route="{{ $url }}"></x-link>
我不喜欢声明变量仅供一次性使用,我喜欢直接传递值。因此,我更喜欢第一种方法。
为什么这个简单的代码不起作用..?
【问题讨论】:
标签: php laravel components parameter-passing