[L5.1] Event listener gets instance of model instead of event itself

Posted 3 years ago by Francismori7

Okay so here's my error, relative to type-hinting of course:

ErrorException in InvalidateClientsCache.php line 24:
Argument 1 passed to App\Listeners\InvalidateClientsCache::handle() must be an instance of App\Events\ClientWasCreated, instance of App\Client given

My EventServiceProvider is as follows:

    protected $listen = [
        ClientWasCreated::class => [

ClientWasCreated is raised from a job called (CreateNewClient) (event(ClientWasCreated::class, [$this->client]);)

ClientWasCreated is like this:

    public function __construct(Client $client)
        $this->client = $client;

InvalidateClientsCache then goes like that in handle():

    public function handle(ClientWasCreated $event) { }

WHY OH WHY does Laravel try to give me an instance of the created Client model? Instead of giving me the supposed ClientWasCreated event instance??

Please sign in or create an account to participate in this conversation.