Php 在嵌套的Laravel 7刀片组件中指定$attributes

Php 在嵌套的Laravel 7刀片组件中指定$attributes,php,laravel,laravel-7,laravel-views,Php,Laravel,Laravel 7,Laravel Views,在Laravel7中,我开始使用视图组件。 我试图将$attributes变量从一个组件传递到另一个组件,如: x-模态分量: <div {{ $attributes->merge(['class' => 'modal fade']) }}> Something great... </div> <x-modal {{ $attributes }}> Something great too </x-modal> merg

在Laravel7中,我开始使用视图组件。 我试图将
$attributes
变量从一个组件传递到另一个组件,如:

x-模态分量:

<div {{ $attributes->merge(['class' => 'modal fade']) }}>
   Something great...
</div>
<x-modal {{ $attributes }}>
    Something great too
</x-modal>
merge(['class'=>'modal fade'])}>
很棒的东西。。。
x-modal-form组件:

<div {{ $attributes->merge(['class' => 'modal fade']) }}>
   Something great...
</div>
<x-modal {{ $attributes }}>
    Something great too
</x-modal>

也很棒
在这种情况下,我在x-modal组件中有一个id属性,如:

<x-modal-form id="aRandomId" title="Test"></x-modal-form>

但在这种情况下,idaRandomId不会扩散到x模态分量。我有一个错误“语法错误,意外的'endif'(T_endif),预期文件结尾”,因为{{$attributes}

你知道怎么做吗?

根据laravel:

不属于组件构造函数的所有属性 将自动添加到组件的“属性包”。这 属性包将通过 $attributes变量。所有属性都可以在 通过回显此变量创建组件

如果在一个视图中嵌套或使用多个组件,并且希望使用属性包,则将公共属性放入此包中,并手动放入唯一属性,如下所示:

<x-modal {{ $attributes }}>
    <x-modal-form {{ $attributes }} id="aRandomId" title="Test">
     // code here
    </x-modal-form>
</x-modal>

//代码在这里

当然,id属性为HTML元素指定了唯一的id。id属性的值在HTML文档中必须是唯一的。

此行为已在Laravel 8中修复:


您现在可以将
$attributes
变量从一个组件传递到另一个组件

您想在同一视图中重复id?!我在另一个组件中使用了一个组件,我想将id传播到deapest组件