app/Http/Controllers/Member/MemberController.php
/**
     * Store a newly created resource in storage.
     *
     * @param \App\Http\Requests\Member\StoreMemberRequest $request
     * @return AccountResource
     */
Store a newly created resource in storage.
Store a newly created resource in storage .
public function store(StoreMemberRequest $request)
    {
        DB::beginTransaction();
        try {
            $contact = ContactServices::createContact($request);
            if ($request->type === "customer") {
                $account = AccountServices::createAccount($request, $contact);
                if ($account->id) {
                    $subscription = SubscriptionServices::createSubscription(
                        $request,
                        $account
                    );
                    $bill = BillingServices::createUIBillingEntry(
                        $request,
                        $account->id
                    );
                    $transaction = TransactionServices::logUITransaction(
                        $request,
                        $account->id,
                        $bill->id
                    );
                    $accountWithContactDetails = Account::with("contact")->find(
                        $account->id
                    );
                    if (
                        $subscription &&
                        $transaction &&
                        $accountWithContactDetails
                    ) {
                        Mail::to($request->email)
                            ->send(
                                new MemberRegistered($account->id)
                            );
                    }
                }
            }
            DB::commit();
            return new AccountResource($accountWithContactDetails);
        } catch (\Exception $exception) {
            DB::rollback();
            return Helper::exceptionJSON($exception, 422, "Member");
        }
    }
public function store ( StoreMemberRequest $ request ) { DB :: beginTransaction ( ) ; try { $ contact = ContactServices :: createContact ( $ request ) ; if ( $ request -> type === " customer " ) { $ account = AccountServices :: createAccount ( $ request , $ contact ) ; if ( $ account -> id ) { $ subscription = SubscriptionServices :: createSubscription ( $ request , $ account ) ; $ bill = BillingServices :: createUIBillingEntry ( $ request , $ account -> id ) ; $ transaction = TransactionServices :: logUITransaction ( $ request , $ account -> id , $ bill -> id ) ; $ accountWithContactDetails = Account :: with ( " contact " ) -> find ( $ account -> id ) ; if ( $ subscription && $ transaction && $ accountWithContactDetails ) { Mail :: to ( $ request -> email ) -> send ( new MemberRegistered ( $ account -> id ) ) ; } } } DB :: commit ( ) ; return new AccountResource ( $ accountWithContactDetails ) ; } catch ( \ Exception $ exception ) { DB :: rollback ( ) ; return Helper :: exceptionJSON ( $ exception , 422 , " Member " ) ; } }
Store a newly created resource in storage.
Store a newly created resource in storage .
// create contact // create account and other registration processes for customer only // if account creation is successful then only process with dispatch request //                    ProcessAdditionalRegistrationSteps::dispatch( //                        $request->all(), //                        $account //                    ); // send email on registration