为什么我的节目主持人没有加入我的活动?

时间:2019-05-30 22:19:59

标签: laravel-5 events listener

我正在尝试在控制器中调用一个事件,该事件应该到达侦听器。侦听器应发送电子邮件。但是,听众永远不会到达。望远镜说我的活动没有主持人。为什么没有附加到我的活动的列表器?

控制器:

namespace App\Http\Controllers;

use App\Match;
use App\Tournament;
use Illuminate\Http\Request;
use Illuminate\Support\Arr;
use App\Events\ToernooiMail as ToernooiMailEvent;

class TournamentController extends Controller
{
 public function store()
 {

    $toernooi = Tournament::create(request([
        'name' => 'name',
    ]));

    event(new ToernooiMailEvent($toernooi));

    return redirect('tournaments');
 }

该事件涉及:

<?php

namespace App\Events;

use Illuminate\Broadcasting\Channel;
use Illuminate\Queue\SerializesModels;
use Illuminate\Broadcasting\PrivateChannel;
use Illuminate\Broadcasting\PresenceChannel;
use Illuminate\Foundation\Events\Dispatchable;
use Illuminate\Broadcasting\InteractsWithSockets;
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;

class ToernooiMail
{
 use Dispatchable, InteractsWithSockets, SerializesModels;

 public $toernooi;

 /**
  * Create a new event instance.
  *
  * @return void
  */
 public function __construct($toernooi)
 {
     $this->toernooi = $toernooi;
 }

 /**
  * Get the channels the event should broadcast on.
  *
  * @return \Illuminate\Broadcasting\Channel|array
  */
 public function broadcastOn()
 {
     return new PrivateChannel('channel-name');
 }
}

未到达的列表器:

 <?php

 namespace App\Listeners;

 use App\Events\ToernooiMail;
 use Illuminate\Queue\InteractsWithQueue;
 use Illuminate\Contracts\Queue\ShouldQueue;
 use App\Mail\toernooiMail as toernooiEmail;


class SendToernooiMail
{
/**
 * Create the event listener.
 *
 * @return void
 */
public function __construct()
{

}

/**
 * Handle the event.
 *
 * @param  ToernooiMail  $event
 * @return void
 */
public function handle(ToernooiMail $event)
{
    \Mail::to('dannylenoir@gmail.com')->send(
        new toernooiEmail($event->toernooi)  
    );
}
}

eventServiceProvider:

<?php

namespace App\Providers;

use Illuminate\Support\Facades\Event;
use Illuminate\Auth\Events\Registered;
use Illuminate\Auth\Listeners\SendEmailVerificationNotification;
use Illuminate\Foundation\Support\Providers\EventServiceProvider as        ServiceProvider;
use App\Events\ToerooiMail;
use App\Listeners\SendToernooiMail;

class EventServiceProvider extends ServiceProvider
{
  /**
   * The event listener mappings for the application.
   *
   * @var array
   */
  protected $listen = [
      Registered::class => [
        SendEmailVerificationNotification::class,
      ],

    ToerooiMail::class => [
        SendToernooiMail::class,
    ],
 ];

  /**
   * Register any events for your application.
   *
   * @return void
   */
 public function boot() 
      parent::boot();

        //
    }

}

我的活动已被调用,但没有到达我的监听器中的电子邮件。 用望远镜说我的活动没有听众。

0 个答案:

没有答案