F
Filamentβ€’10mo ago
MikeG

Calling a livewire PHP method from a custom field component

Hey, I have the need to call a PHP method from the view of a Customer Field Component. If I use $wire.methodName() it states the method doesnt exist on the livewire field component. What's happening is im getting a Javascript event which results in a code, with that code, i need to make an API call and set the state of the field to the result of that API call. Any way to do this?
Solution:
That fixed the issue πŸ™‚
Jump to solution
3 Replies
MikeG
MikeGβ€’10mo ago
For extra context, im getting that event, and trying to call a method on the component
No description
MikeG
MikeGβ€’10mo ago
Ok so digging further, i found https://discord.com/channels/883083792112300104/1158734504635142215/1158734504635142215 So I added
protected function setUp(): void
{
$this->registerListeners([
'meta::retrievedToken' => [
function (MetaEmbeddingTool $component, string $targetStatePath, string $token) {
$token = $token .'2';


$component->state($token);
},
],
]);
}
protected function setUp(): void
{
$this->registerListeners([
'meta::retrievedToken' => [
function (MetaEmbeddingTool $component, string $targetStatePath, string $token) {
$token = $token .'2';


$component->state($token);
},
],
]);
}
and
$wire.dispatchFormEvent('meta::retrievedToken', {{ $getStatePath() }}, e.data.accessToken);
$wire.dispatchFormEvent('meta::retrievedToken', {{ $getStatePath() }}, e.data.accessToken);
But results in
Uncaught ReferenceError: data is not defined
at eval (eval at safeAsyncFunction (livewire.js?id=e2b302e9:1249:21), <anonymous>:5:65)
Uncaught ReferenceError: data is not defined
at eval (eval at safeAsyncFunction (livewire.js?id=e2b302e9:1249:21), <anonymous>:5:65)
Ah, i fell for it πŸ˜‚ My {{ $getStatePath() }} wasnt a string, needed to add quotes '{{ $getStatePath() }}'
Solution
MikeG
MikeGβ€’10mo ago
That fixed the issue πŸ™‚
Want results from more Discord servers?
Add your server