Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

booni3's avatar

[7.x] Blade Components - "Undefined variable" (fails on Vapor only)

I have a simple button component that I am trying to provide some colour logic with a fallback when none is provided.

  • My local machine is running php 7.4.3.
  • Vapor is on 7.4.1 I believe
  • Laravel 7.1.0
<button type="button" 
{{ $attributes->merge(['class' => "inline-flex ".($colour)] }}>
  {{ $slot }}
</button>
class button extends Component
{
    public $colour;

    public function __construct($colour = null)
    {
        if (! $colour) {
            $this->colour = 'blue';
        } else {
            $this->colour = $colour;
        }
    }
...

When passing no variable as below, we get an "Undefined variable" exception, on Vapor only.

<x-button>Save</x-button>

If we then pass in the colour attribute:

<x-button colour='blue'>Save</x-button>

We get the below html on Vapor (note the colour attribute being outputted as HTML)

<button type="button" class="inline-flex" colour="blue">
  Save
</button>

vs. this on local/valet:

<button type="button" class="inline-flex blue">
  Save
</button>

So local works as I would expect, but vapor fails with:

  1. "Undefined variable" exception thrown if we do not pass a variable, even though we are defaulting to a fallback in the class.
  2. When passing in the variable, it does not merge into the attributes.
0 likes
1 reply
booni3's avatar
booni3
OP
Best Answer
Level 3

This was an error with the class name not being capitalized

Please or to participate in this conversation.