Answer the question
In order to leave comments, you need to log in
Laravel doesn't register the lisener for the event, what's the problem?
I am going through a laracast course, I repeated everything as in the video, the event starts, but the lisener does not. Here is the code:
Event
<?php
namespace App\Events;
use Illuminate\Foundation\Events\Dispatchable;
use Illuminate\Queue\SerializesModels;
class ProjectCreated
{
use Dispatchable, SerializesModels;
public $project;
public function __construct($project)
{
$this->project = $project;
}
}
<?php
namespace App\Listeners;
use App\Events\ProjectCreated;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Queue\InteractsWithQueue;
class SendProjectCreatedNotification
{
public function handle(ProjectCreated $event)
{
die('Listener');
}
}
<?php
namespace App\Providers;
use App\Events\ProjectCreated;
use App\Listeners\SendProjectCreatedNotification;
use Illuminate\Auth\Events\Registered;
use Illuminate\Auth\Listeners\SendEmailVerificationNotification;
use Illuminate\Foundation\Support\Providers\EventServiceProvider as ServiceProvider;
use Illuminate\Support\Facades\Event;
class EventServiceProvider extends ServiceProvider
{
protected $listen = [
Registered::class => [
SendEmailVerificationNotification::class,
],
'App\Events\ProjectCreated' => [
'App\Listeners\SendProjectCreatedNotification',
],
];
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question