public function store($communityId, Request $request, Responder $responder)
 {
     $rules = ['name' => 'required', 'email' => 'required|email', 'phone_number' => 'required'];
     return $responder->validateAndRespond($request->all(), $rules, function ($response) use($request, $communityId) {
         $contactFormLead = new Community\ContactFormLead();
         $contactFormLead->name = $request->get('name');
         $contactFormLead->email = $request->get('email');
         $contactFormLead->phone = $request->get('phone_number') ?: '';
         $contactFormLead->reason = $request->get('reason') ?: '';
         $contactFormLead->message = $request->get('message') ?: '';
         $contactFormLead->community_id = $communityId;
         $contactFormLead->new = 1;
         $community = Community\Community::find($communityId);
         if (!$contactFormLead->save()) {
             $response->fails = true;
             $response->messages[] = ['DB', 'Problem sending message. Please try again'];
             return $response;
         }
         $mailer = new \App\RExpress\Email\EmailManager();
         $textStatus = \App\RExpress\Lead\ReasonConverter::textStatus($contactFormLead->reason);
         $createdAt = new \DateTime($contactFormLead->created_at);
         $manager = Community\CommunityManager::where('iCommunityId', '=', $communityId)->first();
         $validator = \Validator::make(['email' => $contactFormLead->email], ['email' => 'email|required']);
         if (!$validator->fails()) {
             try {
                 \App\RExpress\Email\EmailManager::send(['template' => 'lead.emails.default', 'params' => ['communityUrl' => $community->vCommunityURL, 'name' => $contactFormLead->name, 'email' => $contactFormLead->email, 'phone' => $contactFormLead->phone, 'reason' => $textStatus, 'message' => $contactFormLead->message, 'createdAt' => $createdAt->format('F j, Y \\a\\t g:ia')], 'to' => $manager->vEmail, 'subject' => 'Lead submitted at your website ' . $community->vCommunityURL]);
             } catch (\Exception $e) {
             }
         }
         return $response;
     });
 }
 public function store(Request $request, Responder $responder)
 {
     return $responder->validateAndRespond($request->all(), ['community_id' => 'required|numeric', 'name' => 'required', 'email' => 'required|email', 'phone' => 'numeric', 'floor_plan_id' => 'numeric'], function ($response) use($request) {
         $checkAvailabilityLead = new Models\CheckAvailabilityLead();
         $checkAvailabilityLead->community_id = $request->get('community_id');
         $checkAvailabilityLead->name = $request->get('name');
         $checkAvailabilityLead->email = $request->get('email');
         $checkAvailabilityLead->phone = $request->get('phone');
         $checkAvailabilityLead->floor_plan_id = $request->get('floor_plan_id');
         if (!$checkAvailabilityLead->save()) {
             $response->fails = true;
             $response->messages = ['DB', 'Problem sending message. Please try again.'];
             return $response;
         }
         $community = Models\Community\Community::find($checkAvailabilityLead->community_id);
         $createdAt = new \DateTime($checkAvailabilityLead->created_at);
         $floorPlan = Models\FloorPlan\FloorPlan::find($checkAvailabilityLead->floor_plan_id);
         $emails = explode(',', $community->tRefFriendLeadEmails);
         foreach ($emails as $email) {
             $validator = \Validator::make(['email' => $email], ['email' => 'email|required']);
             if (!$validator->fails()) {
                 try {
                     \App\RExpress\Email\EmailManager::send(['template' => 'checkAvailabilityLead.emails.default', 'params' => ['communityUrl' => $community->vCommunityURL, 'name' => $checkAvailabilityLead->name, 'email' => $checkAvailabilityLead->email, 'phone' => $checkAvailabilityLead->phone, 'floorPlanLabel' => $floorPlan->label, 'createdAt' => $createdAt->format('F j, Y \\a\\t g:ia')], 'to' => trim($email), 'subject' => 'Check Availability Lead submitted at your website ' . $community->vCommunityURL]);
                 } catch (\Exception $e) {
                 }
             }
         }
         return $response;
     });
 }