s4muel was awarded Best Answer+1000 XP
4mos ago
@vincent15000 to simplify my response, if you have two sets of users (A, B) and two sets of data to send to them:
- tweak the
EndpointUpdatedevent to support two formats of output data:- full details, for the user (A) that changes the data
- limited details, for the others (B)
- do this by setting a property via a constructor (and switch accordingly in the
broadcastWith()) or just check the users roles, compare the user id to updater id, etc
public function __construct(
public $users,
public $sendFullDetails = false
) {
//
}
public function broadcastWith(): array
{
if ($this->sendFullDetails) {
//full details
} else {
//limited details
}
}
- when firing the event, fire two of them
-
broadcast(new EndpointUpdated([$userA], sendFullDetails: true)); -
broadcast(new EndpointUpdated($usersB, sendFullDetails: false));
-
or if A/B is not enough, just loop each user and fire the event specific for him (and check his rights directly in the broadcastWith())