I am trying to run a javascript library, Noty, upon user login. I've already registered the event and followed the documentation here. However I tried to use echo to send down the javascript, but the code isn't executing from what I can see. The workflow is that upon login in the Home page a noty notification will pop up saying welcome.
Here is my EventServiceProvider:
class EventServiceProvider extends ServiceProvider
{
/**
* The event listener mappings for the application.
*
* @var array
*/
protected $listen = [
Registered::class => [
SendEmailVerificationNotification::class,
],
'Illuminate\Auth\Events\Login' => ['App\Listeners\UserEventListener@onUserLogin']
];
/**
* Register any events for your application.
*
* @return void
*/
public function boot()
{
parent::boot();
}
}
UserEventListener:
class UserEventListener
{
/**
* Create the event listener.
*
* @return void
*/
public function __construct()
{
//
}
/**
* Handle the event.
*
* @param Login $event
* @return void
*/
public function handle(Login $event)
{
}
public function onUserLogin($event) {
echo("<script>
$(document).ready(function() {
new Noty({
text: 'Welcome {{Auth::user()->name}}! ',
type:'info',
layout: 'centerRight',
timeout:2000
})
.on('onShow', function() {
var audio = new Audio('/sounds/appointed.mp3');
audio.play();
}).show();
});
</script>");
echo("adad");
}
}