Home > Blockchain >  How to use @error directive in Laravel Blade Component
How to use @error directive in Laravel Blade Component

Time:02-21

I'm trying to create some reusable component for CSS. Now, I'm stuck here.

Anonymous Components

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

It does not work and throws errors:

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

Does anyone know how to solve this error or alternative way to figure out ?

CodePudding user response:

I guess that Blade's compiler will not catch the @error directive inside the mustaches

{{ @error('name') invalid @enderror }} {{-- invalid code ?--}}

I didn't test exactly your case, but the following code worked for me

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