Undefined variable in custom field

I have very simple form field that i created that extends the simple placeholder component, which looks like so:
<?php

namespace App\Forms\Components;

use Filament\Forms\Components\Placeholder;

class Alert extends Placeholder
{
protected string $view = 'forms.components.alert';
public string $template = 'twui.info-alert';
public mixed $content;

public function type($type): static
{
$this->template = "twui.{$type}-alert";

return $this;
}
}
<?php

namespace App\Forms\Components;

use Filament\Forms\Components\Placeholder;

class Alert extends Placeholder
{
protected string $view = 'forms.components.alert';
public string $template = 'twui.info-alert';
public mixed $content;

public function type($type): static
{
$this->template = "twui.{$type}-alert";

return $this;
}
}
and then the view is
<x-dynamic-component :component="$template">
{{ $getContent() }}
</x-dynamic-component>
<x-dynamic-component :component="$template">
{{ $getContent() }}
</x-dynamic-component>
Right now though its saying that $template is undefined. This worked fine with laravel 9 and filament v3 alpha, but not anymore since upgrading to the latest stable of both. I dont see any changes with the Placeholder class that I am extending though. Any ideas what I might be missing?
4 Replies
Mark Chaney
Mark Chaney5mo ago
anyone? looks like i have to do
<?php

namespace App\Forms\Components;

use Filament\Forms\Components\Placeholder;

class Alert extends Placeholder
{
protected string $view = 'forms.components.alert';
public string $template = 'twui.info-alert';
public mixed $content;

public function type($type): static
{
$this->template = "twui.{$type}-alert";

return $this;
}

public function getTemplate(): string
{
return $this->template;
}
}
<?php

namespace App\Forms\Components;

use Filament\Forms\Components\Placeholder;

class Alert extends Placeholder
{
protected string $view = 'forms.components.alert';
public string $template = 'twui.info-alert';
public mixed $content;

public function type($type): static
{
$this->template = "twui.{$type}-alert";

return $this;
}

public function getTemplate(): string
{
return $this->template;
}
}
and then $getTemplate() in the blade. Livewire 3 change?
Andrew Wallo
Andrew Wallo5mo ago
Properties for custom components should always have a get and set method associated with them.
Mark Chaney
Mark Chaney5mo ago
well somehow i got away with it for a year
Andrew Wallo
Andrew Wallo5mo ago
Hmm weird. I thought that was always how it’s been.
Want results from more Discord servers?
Add your server
More Posts