2016-08-06 16 views
0

私はLaravel 5.0。*を使用しており、次の回答に従っています:login event handling in laravel 5しかし、私はまだイベントの発射を見ることができません。イベントが発生しないLaravel 5.0。*

誰もがこれで私を助けることができる:

これは私のイベントハンドラクラスがどのように見えるかです:

<?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

試しましたか? [docs show](https://laravel.com/docs/5.0/events)とまったく同じことをして、それが最初に機能するかどうかを確認してください。 – Ohgodwhy

+0

@Ohgodwhyはい、私はまったく同じことをしましたが、まだ動作していません...私は自分のコードに何か間違いや欠けているものは見られません、なぜ私はauth.loginが全く発砲しないのかわかりません... – mizlul

+0

も試しましたイベント:: listen( 'auth.login'、function($ event) { //イベントの処理... }); ()メソッドから直接、変更はありません。イベントは発生しません。 – mizlul

答えて

0

私はLaravel 5.2を使用しています。リスナーが$ listen配列のイベントクラス名のスペルを間違っていることを知らないうちに、リスナーが応答しない理由を理解しようと時間を費やしました。イベントのようなイベント(新しいSameEventClass(...))を発生させる場合、基本的に$ listen => ['SameEventClass' => ['SameListener']で使用したのと同じ名前を使用してください。

関連する問題