Passing PHP variables into my Livewire action parameter crashes it.
@php {{ $tel = 'telephone'; }} @endphp
<button wire:click="sortBy({{$tel}})">
Add Todo
</button>
This is the error message in my console:
VM527:8 Uncaught ReferenceError: telephone is not defined
at eval (eval at value (wire-directives.js:93:24), <anonymous>:8:16)
at Directive.value (wire-directives.js:100:22)
at Directive.get (wire-directives.js:58:33)
at node_initializer.js:209:42
at Component.value (index.js:582:9)
at HTMLButtonElement.<anonymous> (node_initializer.js:201:23)
When I pass a simple string into the same method it works i.e
<button wire:click="sortBy('telephone')">
Add Todo
</button>
CodePudding user response:
You already answered your own question. You're passing a string but you're not quoting it, so it's not evaluated as one.
@php {{ $tel = 'telephone'; }} @endphp
<button wire:click="sortBy('{{$tel}}')">
Add Todo
</button>