Hello I’m facing this problem. I have this 2 listeners which are the same.
What I do not understand is that in SendTargetCompletedNotification when trying to access $event->client->contacts I get the error Undefined property: IlluminateDatabaseEloquentRelationsBelongsTo::$contacts but doing the same in SendTargetAssignedContactNotification works. Also if I access $client->contacts before entering SendTargetCompletedNotification It returns the contacts, so it should work apparently.
<?php
namespace AppListeners;
use AppEventsTargetCompleted;
use AppNotificationsTargetCompletedContactNotification;
use IlluminateContractsQueueShouldQueue;
use IlluminateQueueInteractsWithQueue;
use IlluminateSupportFacadesNotification;
class SendTargetCompletedContactNotification
{
/**
* Create the event listener.
*
* @return void
*/
public function __construct()
{
//
}
/**
* Handle the event.
*
* @param AppProvidersTargetCompleted $event
* @return void
*/
public function handle(TargetCompleted $event)
{
dd($event->client->contacts);
foreach($event->client->contacts as $contact) {
$contact->notify(new TargetCompletedContactNotification($event->kpi, $event->points));
}
}
}
<?php
namespace AppListeners;
use AppEventsTargetAssigned;
use AppNotificationsTargetAssignedContactNotification;
use IlluminateContractsQueueShouldQueue;
use IlluminateQueueInteractsWithQueue;
use IlluminateSupportFacadesNotification;
class SendTargetAssignedContactNotification
{
/**
* Create the event listener.
*
* @return void
*/
public function __construct()
{
//
}
/**
* Handle the event.
*
* @param AppProvidersTargetAssigned $event
* @return void
*/
public function handle(TargetAssigned $event)
{
dd($event->client->contacts);
foreach ($event->client->contacts as $contact) {
$contact->notify(new TargetAssignedContactNotification($event->kpi, $event->causer));
}
}
}