Create and use your own helper functions.
Dec 14, 2020
6
Level 1
Calling livewire method inside blade template
I am trying to call a livewire component method inside the blade template, but I am getting an "undefined method called" error. Do there any workaround to solve this problem?
Livewire Component::
class AskQuestion extends Component {
public function convertNumber($engNum) {
...
return $convertedNumber;
}
}
The blade template looks like::
<select wire:model="dob.year" type="text" class="mt-1">
@foreach($years as $engYear )
<option >{{ convertNumber($engYear) }}</option>
@endforeach
</select>
Level 1
I found a better solution in this article
https://ryangjchandler.co.uk/articles/accessing-helper-methods-in-your-livewire-components .
We can directly call method inside view as $this->methodName()
Just knew that this feature is available and is not documented in livewire docs.
7 likes
Please or to participate in this conversation.