Files
MKM/app/Actions/Account/StoreAccount.php
2024-08-11 20:03:49 +08:00

29 lines
736 B
PHP

<?php
namespace App\Actions\Account;
use App\Actions\BaseAction;
use App\Commands\Account\CreateAccountCommand;
use App\DataObjects\CreateAccountDTO;
use Closure;
use Exception;
use LogicException;
use Spatie\LaravelData\Data;
class StoreAccount extends BaseAction
{
public function __construct(private readonly CreateAccountCommand $createAccountCommand) {}
public function __invoke(CreateAccountDTO|Data $payload, Closure $next)
{
try {
$payload->account = $this->createAccountCommand->execute($payload->data);
return $next($payload);
} catch (Exception $exception) {
throw new LogicException('Error Storing Account: '.$exception->getMessage());
}
}
}