Conditional Styling with Attributes

  • The $attributes->class() method accepts an array where keys are CSS classes and values are booleans
  • This allows dynamic styling based on component state
  • When multiple conditional classes apply, standard CSS specificity determines the result
<input {{ $attributes->class([
    'border-gray-300' => !$hasError,
    'border-red-500' => $hasError,
    'rounded-md shadow-sm',
    'focus:border-indigo-300 focus:ring focus:ring-indigo-200',
]) }}
    type="{{ $type }}"
    id="{{ $name }}"
/>

← / → navigate · N notes · Esc exit