File: D:/HostingSpaces/SBogers10/shop.komma.nl/app/Listeners/Registered.php
<?php declare(strict_types=1);
namespace App\Listeners;
use App\Addresses\AddressServiceInterface;
use App\Users\SiteUserInterface;
use Illuminate\Auth\Events\Registered as RegisteredEvent;
use Komma\KMS\Auth\AuthMailServiceInterface;
class Registered
{
protected AddressServiceInterface $addressService;
protected AuthMailServiceInterface $authMailService;
/**
* Create the event listener.
*
* @return void
*/
public function __construct()
{
$this->addressService = app(AddressServiceInterface::class);
$this->authMailService = app(AuthMailServiceInterface::class);
}
/**
* Handle the event.
*
* @param RegisteredEvent $event
* @return void
*/
public function handle(RegisteredEvent $event)
{
/** @var SiteUserInterface $siteUser */
$siteUser = $event->user;
$address = $this->addressService->getAddressFromInput();
$address->first_name = $siteUser->first_name;
$address->last_name_prefix = $siteUser->last_name_prefix;
$address->last_name = $siteUser->last_name;
$address->siteUser()->associate($siteUser);
$address->save();
$siteUser->accountAddress()->associate($address);
$siteUser->shippingAddress()->associate($address);
$siteUser->invoiceAddress()->associate($address);
$siteUser->save();
}
}