'Laravel Blade Component - Pass property with colon in the middle and access from class
I have the following code in a Livewire Component
<x-input.color
wire:model="foo.name"
wire-test="foo.name"
/>
So I am trying to use a Blade Component and pass both properties to the class.
class Color extends Component
{
public $wireTest;
public $wireModel;
public function __construct($wireTest = null, $wireModel = null)
{
$this->wireTest = $wireTest; // will resolve
$this->wireModel = $wireModel; // wont resolve
dump($this->data()); // will resolve the attribute bag thats empty
}
public function render()
{
dump($this->data()); // will resolve the attribute bag thats empty
return view('components.input.color');
}
}
color.blade.php
<input {{$attributes}} ... />
//$attributes will contain 'wire:model' => 'foo.name'
I cannot figure out how to pass access a property with a : in the middle of the name: ie wire:model within the class
Is there anyway I can access the wire:model attribute within the class?
Solution 1:[1]
You don’t have to pass a variable with a : in the attribute:
return view('components.input.color', [‘model’ => $this->wireModel, ‘test’ => $thid->wireTest]);
And then in your test use those as followed
<input wire:model=“{{ $model }}” wire-test=“{{ $test }}” />
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | John Zwarthoed |
