Laravel自定义组件参数解析问题
Laravel custom component parameter parsing issue
在我的 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>
我不喜欢声明变量只供单独使用,我喜欢直接传递值。所以,我更喜欢第一种方法。
为什么这个简单的代码不起作用..?
我发现如果值与它们绑定,参数会更好地工作。
<x-link icon="{{ $icon }}" :route="route('admin.' . $route . '.create')" />
此外...如果需要多个值:
<x-link icon="{{ $icon }}" :route="route('admin.' . $route . '.create')" :params="[
'key1' => 'value1',
'key2' => [
...
],
]" />
在我的 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>
我不喜欢声明变量只供单独使用,我喜欢直接传递值。所以,我更喜欢第一种方法。
为什么这个简单的代码不起作用..?
我发现如果值与它们绑定,参数会更好地工作。
<x-link icon="{{ $icon }}" :route="route('admin.' . $route . '.create')" />
此外...如果需要多个值:
<x-link icon="{{ $icon }}" :route="route('admin.' . $route . '.create')" :params="[
'key1' => 'value1',
'key2' => [
...
],
]" />