src/Http/Controllers/FrontendListSubscribeController.php
public function postSubscribe(Request $request) {

        // Does the email ID exist in the "list_emails" table for this list ID already?
        // We need the email ID, but only have an email address. See if this email address exists in the "emails" db table
        if ($this->subscribeToList->getEmailIDByTitle($request->input('email'))) {

            // yes, the email address exists in the "emails" db table
            if ($this->subscribeToList->getList_emailByEmailIdAndListId(
                   $this->subscribeToList->getEmailIDByTitle($request->input('email')),
                   $request->input('listID')
                )
            ) {
                return view('lasallecrmlistmanagement::subscribe-unsubscribe-list.subscribe_email_already_in_list', [
                    'title'             => $this->subscribeToList->getListnameByListId($request->input('listID')),
                    'email'             => $request->input('email')
                ]);
            }

        }


        // Add email to the email list
        $emailID = $this->subscribeToList->getEmailIDByTitle($request->input('email'));

        if (!$emailID) {

            // The email address does NOT exist in the "emails" db table.
            // So, create the email address in the "emails" db table
            // (i) prep the data
            $data = $this->subscribeToList->prepareEmailDataForInsert($request);

            // (ii) create the new record
            $emailID = $this->subscribeToList->createNewEmailRecord($data);
        }

        // if the INSERT to the "emails" db table failed, then try the subscribe all over again
        if (!$emailID) {
            $message = "Something did not quite go right in the processing. Please try again.";
            Session::flash('message', $message);
            return redirect('list/subscribe/'.$request->input('listID'))
                ->withInput()
            ;
        }


        // INSERT INTO list_email
        // consolidate POST vars and processed data into one array
        $input = array_merge($request->all(),['emailID' => $emailID]);

        // prep the data for the INSERT
        $data = $this->subscribeToList->prepareList_emailDataForInsert($input);

        // INSERT record
        $list_emailID = $this->subscribeToList->createNewList_emailRecord($data);

        // if the INSERT into the "list_email" db table failed, then try the subscribe all over again
        if (!$list_emailID) {
            $message = "Something did not go quite right in the processing. Please try again.";
            Session::flash('message', $message);
            return redirect('list/subscribe/'.$request->input('listID'))
                ->withInput()
                ;
        }


        if ($request->has('surname')) {


            $peopleID = $this->subscribeToList->isFirstnameSurname($request->input('first_name'), $request->input('surname'));

            if (!$peopleID) {
                // prep the data for the INSERT
                $data = $this->subscribeToList->preparePeoplesDataForInsert($input);

                // INSERT record
                $peopleID = $this->subscribeToList->createNewPeoplesRecord($data);
            }


            if ($peopleID) {
                // INSERT INTO people_email
                $people_emailID = $this->subscribeToList->createNewPeople_emailRecord(['people_id' => $peopleID, 'email_id' => $emailID]);
            }


            if (!$people_emailID) {
                // whaddaya mean the INSERT INTO "people_email" failed?! try again...
                $people_emailID = $this->subscribeToList->createNewPeople_emailRecord(['people_id' => $peopleID, 'email_id' => $emailID]);
            }
        }

        return view('lasallecrmlistmanagement::subscribe-unsubscribe-list.subscribe_success', [
            'title'             => $this->subscribeToList->getListnameByListId($request->input('listID')),
            'email'             => $request->input('email')
        ]);
    }
public function postSubscribe(Request $request) {

        // Does the email ID exist in the "list_emails" table for this list ID already?
        // We need the email ID, but only have an email address. See if this email address exists in the "emails" db table
        if ($this->subscribeToList->getEmailIDByTitle($request->input('email'))) {

            // yes, the email address exists in the "emails" db table
            if ($this->subscribeToList->getList_emailByEmailIdAndListId(
                   $this->subscribeToList->getEmailIDByTitle($request->input('email')),
                   $request->input('listID')
                )
            ) {
                return view('lasallecrmlistmanagement::subscribe-unsubscribe-list.subscribe_email_already_in_list', [
                    'title'             => $this->subscribeToList->getListnameByListId($request->input('listID')),
                    'email'             => $request->input('email')
                ]);
            }

        }


        // Add email to the email list
        $emailID = $this->subscribeToList->getEmailIDByTitle($request->input('email'));

        if (!$emailID) {

            // The email address does NOT exist in the "emails" db table.
            // So, create the email address in the "emails" db table
            // (i) prep the data
            $data = $this->subscribeToList->prepareEmailDataForInsert($request);

            // (ii) create the new record
            $emailID = $this->subscribeToList->createNewEmailRecord($data);
        }

        // if the INSERT to the "emails" db table failed, then try the subscribe all over again
        if (!$emailID) {
            $message = "Something did not quite go right in the processing. Please try again.";
            Session::flash('message', $message);
            return redirect('list/subscribe/'.$request->input('listID'))
                ->withInput()
            ;
        }


        // INSERT INTO list_email
        // consolidate POST vars and processed data into one array
        $input = array_merge($request->all(),['emailID' => $emailID]);

        // prep the data for the INSERT
        $data = $this->subscribeToList->prepareList_emailDataForInsert($input);

        // INSERT record
        $list_emailID = $this->subscribeToList->createNewList_emailRecord($data);

        // if the INSERT into the "list_email" db table failed, then try the subscribe all over again
        if (!$list_emailID) {
            $message = "Something did not go quite right in the processing. Please try again.";
            Session::flash('message', $message);
            return redirect('list/subscribe/'.$request->input('listID'))
                ->withInput()
                ;
        }


        if ($request->has('surname')) {


            $peopleID = $this->subscribeToList->isFirstnameSurname($request->input('first_name'), $request->input('surname'));

            if (!$peopleID) {
                // prep the data for the INSERT
                $data = $this->subscribeToList->preparePeoplesDataForInsert($input);

                // INSERT record
                $peopleID = $this->subscribeToList->createNewPeoplesRecord($data);
            }


            if ($peopleID) {
                // INSERT INTO people_email
                $people_emailID = $this->subscribeToList->createNewPeople_emailRecord(['people_id' => $peopleID, 'email_id' => $emailID]);
            }


            if (!$people_emailID) {
                // whaddaya mean the INSERT INTO "people_email" failed?! try again...
                $people_emailID = $this->subscribeToList->createNewPeople_emailRecord(['people_id' => $peopleID, 'email_id' => $emailID]);
            }
        }

        return view('lasallecrmlistmanagement::subscribe-unsubscribe-list.subscribe_success', [
            'title'             => $this->subscribeToList->getListnameByListId($request->input('listID')),
            'email'             => $request->input('email')
        ]);
    }
public function postSubscribe ( Request $ request ) { // Does the email ID exist in the "list_emails" table for this list ID already? // We need the email ID, but only have an email address. See if this email address exists in the "emails" db table if ( $ this -> subscribeToList -> getEmailIDByTitle ( $ request -> input ( 'email' ) ) ) { // yes, the email address exists in the "emails" db table if ( $ this -> subscribeToList -> getList_emailByEmailIdAndListId ( $ this -> subscribeToList -> getEmailIDByTitle ( $ request -> input ( 'email' ) ) , $ request -> input ( 'listID' ) ) ) { return view ( 'lasallecrmlistmanagement::subscribe-unsubscribe-list.subscribe_email_already_in_list' , [ 'title' => $ this -> subscribeToList -> getListnameByListId ( $ request -> input ( 'listID' ) ) , 'email' => $ request -> input ( 'email' ) ] ) ; } } // Add email to the email list $ emailID = $ this -> subscribeToList -> getEmailIDByTitle ( $ request -> input ( 'email' ) ) ; if ( ! $ emailID ) { // The email address does NOT exist in the "emails" db table. // So, create the email address in the "emails" db table // (i) prep the data $ data = $ this -> subscribeToList -> prepareEmailDataForInsert ( $ request ) ; // (ii) create the new record $ emailID = $ this -> subscribeToList -> createNewEmailRecord ( $ data ) ; } // if the INSERT to the "emails" db table failed, then try the subscribe all over again if ( ! $ emailID ) { $ message = "Something did not quite go right in the processing. Please try again." ; Session :: flash ( 'message' , $ message ) ; return redirect ( 'list/subscribe/' . $ request -> input ( 'listID' ) ) -> withInput ( ) ; } // INSERT INTO list_email // consolidate POST vars and processed data into one array $ input = array_merge ( $ request -> all ( ) , [ 'emailID' => $ emailID ] ) ; // prep the data for the INSERT $ data = $ this -> subscribeToList -> prepareList_emailDataForInsert ( $ input ) ; // INSERT record $ list_emailID = $ this -> subscribeToList -> createNewList_emailRecord ( $ data ) ; // if the INSERT into the "list_email" db table failed, then try the subscribe all over again if ( ! $ list_emailID ) { $ message = "Something did not go quite right in the processing. Please try again." ; Session :: flash ( 'message' , $ message ) ; return redirect ( 'list/subscribe/' . $ request -> input ( 'listID' ) ) -> withInput ( ) ; } if ( $ request -> has ( 'surname' ) ) { $ peopleID = $ this -> subscribeToList -> isFirstnameSurname ( $ request -> input ( 'first_name' ) , $ request -> input ( 'surname' ) ) ; if ( ! $ peopleID ) { // prep the data for the INSERT $ data = $ this -> subscribeToList -> preparePeoplesDataForInsert ( $ input ) ; // INSERT record $ peopleID = $ this -> subscribeToList -> createNewPeoplesRecord ( $ data ) ; } if ( $ peopleID ) { // INSERT INTO people_email $ people_emailID = $ this -> subscribeToList -> createNewPeople_emailRecord ( [ 'people_id' => $ peopleID , 'email_id' => $ emailID ] ) ; } if ( ! $ people_emailID ) { // whaddaya mean the INSERT INTO "people_email" failed?! try again... $ people_emailID = $ this -> subscribeToList -> createNewPeople_emailRecord ( [ 'people_id' => $ peopleID , 'email_id' => $ emailID ] ) ; } } return view ( 'lasallecrmlistmanagement::subscribe-unsubscribe-list.subscribe_success' , [ 'title' => $ this -> subscribeToList -> getListnameByListId ( $ request -> input ( 'listID' ) ) , 'email' => $ request -> input ( 'email' ) ] ) ; }
Subscribe someone to a LaSalleCRM email list from the filled in subscribe form

@param  \Illuminate\Http\Request  $request
@return \Illuminate\Http\Response
Subscribe someone to a LaSalleCRM email list from the filled in subscribe form