probably easiest is to have a component on the page that uses wire:poll to check the status of the account. When the status changes to linked (or whatever) you can show a confirmation on the page. Far easier than broadcasting which is more for sending the same content to multiple users. Since your user is sat there waiting for the linking, you can use polling.
Trigger JavaScript on a page (e.g. Toast notification) via API Callback - can it be done with Livewire?
I'm not understanding the interaction between Livewire, Laravel PHP, JavaScript events, and broadcasting.
For my application I want to trigger JavaScript on a page, say for example show a Toast notification, when I receive a post request from a 3rd party website. I believe I can do this with laravel-sockets and Laravel Echo but the overhead seems huge just to get notifications working.
I guess the part I don't exactly understand is how would a PHP backend (from an arbitrary page or route) communicate directly to an HTML page and trigger JavaScript on that page...
Longer explanation:
- My supplier give me JavaScript to launch an iFrame that connects to the Bank.
To launch the iFrame the supplier's JavaScript header is this:
bankLinkBtn.addEventListener('click', function() {
window.banklink.open({
fastLinkURL: '<?php echo $bankLinkURL; ?>',
jwtToken: 'Bearer <?php echo $token; ?> ',
params: {
workflowFlow: 'Consolidation',
callback: '<?php echo $callback; ?>',
},
onSuccess: function(data) {
console.log(data);
},
onError: function(data) {
console.log(data);
},
...
- The route in my web application is this:
Route::get('/bank/callback', [Controllers\BankApiController::class, 'callback'])->name('bank.callback');
What I want to do in the callback method on the Bank API Controller is to refer back to the original JavaScript page and trigger a toast notification, say "Linking complete!".
So the direct path that seems unclear in my mind is:
Can one set an API route direct to a Livewire component page?
Can I "anywhere" on my Laravel app "contact" this Livewire page and do something with the JavaScript?
Or do I have to use Websockets and event broadcasting?
Please or to participate in this conversation.