You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

52 lines
1.9 KiB

  1. <?php
  2. namespace App\Listeners;
  3. use App\Channels\FcmChannel;
  4. use App\Events\BusinessUserCreate;
  5. use App\Models\Business;
  6. use App\Models\User;
  7. use App\Notifications\DBNotification;
  8. use App\Notifications\FcmNotification;
  9. use App\Notifications\MailNotification;
  10. use Illuminate\Contracts\Queue\ShouldQueue;
  11. use Illuminate\Queue\InteractsWithQueue;
  12. use Illuminate\Support\Facades\Notification;
  13. class BusinessUserCreateNotif
  14. {
  15. /**
  16. * Create the event listener.
  17. *
  18. * @return void
  19. */
  20. public function __construct()
  21. {
  22. //
  23. }
  24. /**
  25. * Handle the event.
  26. *
  27. * @param BusinessUserCreate $event
  28. * @return void
  29. */
  30. public function handle(BusinessUserCreate $event)
  31. {
  32. $payload = $event->message;
  33. $new_user = User::findOrFail($payload->data->original->user_id);
  34. $owners = Business::findOrFail($payload->business)->owners()->where('id', '!=', $new_user->id)->get();
  35. $notif = [
  36. 'greeting' => __('notification.'.$payload->data->table_name.'.'.enum('cruds.inverse.'.$payload->data->crud_id.'.singular_name').'.greeting'),
  37. 'subject' => __('notification.'.$payload->data->table_name.'.'.enum('cruds.inverse.'.$payload->data->crud_id.'.singular_name').'.subject'),
  38. 'title' => __('notification.'.$payload->data->table_name.'.'.enum('cruds.inverse.'.$payload->data->crud_id.'.singular_name').'.title'),
  39. 'body' => __('notification.'.$payload->data->table_name.'.'.enum('cruds.inverse.'.$payload->data->crud_id.'.singular_name').'.body', ['business' => request('_business_info')['name'], 'user' => $new_user->name])
  40. ];
  41. $users = $owners->prepend($new_user);
  42. Notification::send($users, new MailNotification($notif));
  43. Notification::send($users, new DBNotification($notif));
  44. Notification::send($users, new FcmNotification($notif));
  45. }
  46. }