What seems to be the problem:
I want to be able to pass HTML attributes to elements rendered by Livewire components a la Blade, but it doesn’t seem to be possible w/o custom code.
I know I can specify each attribute I want with public properties, but I’d like to avoid that for things like class
, name
, id
, autofocus
, etc.
Steps to Reproduce:
- Create a simple Livewire component with
{{ $attributes }}
. - Use it in a template and pass a simple attribute like
class="p-2"
. - See errors.
Are you using the latest version of Livewire:
Yes, just installed 1.2.0 yesterday.
Do you have any screenshots or code examples:
resources/views/livewire/input.blade.php
<input {{ $attributes }}>
app/Http/Livewire/Input.php
<?php
namespace App\Http\Livewire;
use Livewire\Component;
class Input extends Component
{
public function render()
{
return view('livewire.input');
}
}
Template
<div>
<livewire:input class="p-2"/>
</div>
Error
Livewire\Exceptions\MountMethodMissingException
Livewire encountered a missing mount method when trying to initialise the [input] component. When passing component parameters, make sure you have a mount method.
…or with a mount
method
ErrorException
Undefined variable: attributes (View: resources/views/livewire/input.blade.php) (View: resources/views/livewire/input.blade.php) (View: resources/views/livewire/input.blade.php)