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.

CreateEmployeeContact.php 725B

12345678910111213141516171819202122232425262728293031323334
  1. <?php
  2. namespace App\Listeners;
  3. use App\Enums\Common\ContactType;
  4. use Wallo\FilamentCompanies\Events\CompanyEmployeeAdded;
  5. class CreateEmployeeContact
  6. {
  7. /**
  8. * Create the event listener.
  9. */
  10. public function __construct()
  11. {
  12. //
  13. }
  14. /**
  15. * Handle the event.
  16. */
  17. public function handle(CompanyEmployeeAdded $event): void
  18. {
  19. $company = $event->company;
  20. $employee = $event->user;
  21. $company->contacts()->create([
  22. 'type' => ContactType::Employee,
  23. 'name' => $employee->name,
  24. 'email' => $employee->email,
  25. 'created_by' => $company->owner->id,
  26. 'updated_by' => $company->owner->id,
  27. ]);
  28. }
  29. }