如何在 Laravel Blade 组件中使用 @error 指令

How to use @error directive in Laravel Blade Component

我正在尝试为 CSS 创建一些可重用的组件。现在,我被困在这里了。

匿名组件

<input {{ $attributes->merge(['class' =>'block w-full px-3 py-2.. @error('name') invalid @enderror ']) }} />

它不起作用并抛出错误:

syntax error, unexpected identifier "name", expecting "]"

有谁知道如何解决这个错误或找出其他方法吗?

Blade 的编译器不会捕获胡须内的 @error 指令

{{ @error('name') invalid @enderror }}
<input
@error('name')
  {{ $attributes->merge(['class' => 'block w-full px-3 py-2 invalid']) }}
@else
  {{ $attributes->merge(['class' => 'block w-full px-3 py-2']) }}
@enderror
/>
<input {{ $attributes->class(['form-control', 'is-invalid' =>  $errors->has($name)]) }} name="{{ $name }}" value="{{ old($name, $value) }}">