multicaret / laravel-acquaintances

This package gives Eloquent models the ability to manage friendships (with groups), followships along with Likes, favorites..etc.
https://laravel-news.com/manage-friendships-likes-and-more-with-the-acquaintances-laravel-package
MIT License
814 stars 72 forks source link

Unable to get recipient model when listening to event. #102

Closed ltlacerda closed 1 year ago

ltlacerda commented 1 year ago

The event is being listened to by FriendshipSentListener in EventServiceProvider.php:

'acq.friendships.sent' => [ FriendshipSentListener::class ]

Here the FriendshipSentListener's handle() method:

public function handle(object $event): void { dd($event); }

$event comes only with the sender model, not an array or object containing the sender and recipient model.

When I change handle method to receive $event as array, I get the following error:

TypeError: App\Listeners\FriendshipSentListener::handle(): Argument #1 ($event) must be of type array, App\Models\User given, called in /var/www/html/vendor/laravel/framework/src/Illuminate/Events/Dispatcher.php on line 441 in file /var/www/html/app/Listeners/FriendshipSentListener.php on line 21

So I understand that $event only corresponds to the sender model.

Am I doing something wrong?

Thanks in advance.

ltlacerda commented 1 year ago

My mistake. I just added one more argument to handle() and now I have sender and recipient:

public function handle(object $sender, object $recipient): void { dd($sender->name.' '.$recipient->name); }

mkwsra commented 1 year ago

I'm glad it's fixed, and I wish you the best, thanks for using Laravel Acquaintances <3

ltlacerda commented 1 year ago

Thank you very much, bro! You saved me a lot of work. I wish you the best.