Im trying to call an event within my controller.That event should reach for a listener. The listener should send an email. But the listener never gets reached. Telescope says that my event doesn't have a listner. Why is there no listner attached to my event?
Controller:
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');
}
The event thats reached for:
<?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');
}
}
The listner that isn't reached:
<?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)
);
}
}
The 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();
//
}
}
My event is called, but it doens't reach the email in my listener. In telescope it says that my event doesn't have a listener.
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire