我正在使用Laravel 5.0。*并遵循以下答案:login event handling in laravel 5但我仍然无法看到事件触发。
任何人都可以帮助我:
这就是我的事件处理程序类的样子:
<?php namespace App\Handlers\Events;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldBeQueued;
use App\User;
use Illuminate\Support\Facades\Log;
class AuthLoginEventHandler {
/**
* Create the event handler.
*
* @return void
*/
public function __construct()
{
//
}
/**
* Handle the event.
*
* @param User $user
* @param $remember
* @return void
*/
public function handle(User $user, $remember)
{
//
$user->login_counter = 1;
$user->save();
// $user->increment('login_counter');
Log::error('something wrong happened');
// dd("login fired and handled by class with User instance and remember variable");
}
}
这是EventServiceProvider:
<?php namespace App\Providers;
use Illuminate\Contracts\Events\Dispatcher as DispatcherContract;
use Illuminate\Foundation\Support\Providers\EventServiceProvider as ServiceProvider;
class EventServiceProvider extends ServiceProvider {
/**
* The event handler mappings for the application.
*
* @var array
*/
protected $listen = [
'auth.login' => [
'App\Handlers\Events\AuthLoginEventHandler',
],
];
/**
* Register any other events for your application.
*
* @param \Illuminate\Contracts\Events\Dispatcher $events
* @return void
*/
public function boot(DispatcherContract $events)
{
parent::boot($events);
//
}
}
感谢您的帮助
答案 0 :(得分:0)
我使用Laravel 5.2。我花了好几个小时试图弄清楚为什么我的监听器没有响应而不知道我在$ listen数组中错误拼写了事件类名。基本上,如果您像事件一样触发事件(新的SameEventClass(...)),请确保它与您在$ listen =&gt;中使用的名称相同。 [&#39; SameEventClass&#39; =&GT; [&#39; SameListener&#39;]]