I am using laravel 5.4 for creating my project and i used auth controller for login and register what I need is to get the last login time of user and store it in database when i referred that i came about an idea of creating event listeners and i done it..
login event handling in laravel 5
This is in my
EventServiceProvider.php
<?php
namespace App\Providers;
use Illuminate\Support\Facades\Event;
use Illuminate\Foundation\Support\Providers\EventServiceProvider as ServiceProvider;
class EventServiceProvider extends ServiceProvider
{
/**
* The event listener mappings for the application.
*
* @var array
*/
protected $listen = [
'App\Events\SomeEvent' => [
'App\Listeners\EventListener',
],
'Illuminate\Auth\Events\Login' => [
'App\Listeners\AuthLoginListener',
],
];
/**
* Register any events for your application.
*
* @return void
*/
public function boot()
{
parent::boot();
}
}
I defined listener as AuthLoginListner and my
> AuthLoginListner.php
<?php
namespace App\Listeners;
use Carbon\Carbon;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
use App\User;
use Illuminate\Auth\Events\Login;
class AuthLoginListener
{
/**
* Create the event listener.
*
* @return void
*/
public function __construct()
{
//
}
/**
* Handle the event.
*
* @param auth.login $event
* @return void
*/
public function handle(Login $event)
{
return "yes";
}
}
Here i just return one text now what my doubt is how its working and where i get this yes message it doesnot show me any error now have an doubt its working correcty or not if yes where i get this message ..please any one help me out i just confused with this ...