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.

46 lines
1.3 KiB

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