How to Work with Events in Laravel?

Asked

Viewed 49 times

0

Hello I am currently working with an access verification project. I need that when the person has access granted by the system triggers a sound "successfully authorized passage", my question is I can do this with Events of the Laravel?

  • 1

    It doesn’t. Laravel’s events are for dealing with backend and treat them asynchronously through the execution queues. Emitting a sound seems to be the responsibility of the frontend and probably thing to be done with Javascript.

  • Thanks for the answer! You would indicate me a way to do via JS?

1 answer

1


He can, but he also has other ways of doing it. You can record Flash Data, which gives you a 1 cycle life only (once updated the page it ceases to exist) and you execute a scritp when the flash exists, ie when log in for the first time you define the flash, check if it exists, run javascript (audio) and when the user changes pages there will no longer be that flash and also the audio will only play again.

Controller :

Session::flash('message', 'This is a message!'); 

View

@if(Session::has('message'))
<script ......> </script>
endif

https://laravel.com/docs/5.8/session#storing-data

Browser other questions tagged

You are not signed in. Login or sign up in order to post.