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)
 {
     $message = (object) array('fails' => false);
     $validator = \Validator::make($request->all(), ['first_name' => 'required', 'last_name' => 'required', 'email' => 'required|email', 'apartment_id' => 'required', 'phone_number' => 'required', 'description' => 'required']);
     if ($validator->fails()) {
         $message->fails = true;
         $message->messages = $validator->messages();
     } else {
         $community = Community\Community::find($request->get('community_id'));
         // Check if community is yardi
         $maintenanceRequest = new \MaintenanceRequest\MaintenanceRequest();
         $maintenanceRequest->first_name = $request->get('first_name');
         $maintenanceRequest->last_name = $request->get('last_name');
         $maintenanceRequest->email = $request->get('email');
         $maintenanceRequest->phone_number = $request->get('phone_number');
         $maintenanceRequest->pets = $request->get('pets') ? 1 : 0;
         $maintenanceRequest->permission = $request->get('permission') ? 1 : 0;
         $maintenanceRequest->description = $request->get('description');
         $maintenanceRequest->apartment_id = $request->get('apartment_id');
         if ($maintenanceRequest->save()) {
             $communityManager = Community\CommunityManager::where('iCommunityId', '=', $community->iCommunityId)->first();
             $cmEmails = array_map('trim', explode(',', $communityManager->vEmail));
             foreach ($cmEmails as $email) {
                 $validator = \Validator::make(['email' => $email], ['email' => 'email|required']);
                 if (!$validator->fails()) {
                     try {
                         $this->sendNotificationEmail($email, 'maintenanceRequest.notificationEmails.store', 'New Maintenance Requeset Added', $maintenanceRequest);
                     } catch (\Exception $e) {
                     }
                 }
             }
             $message->maintenanceRequestId = $maintenanceRequest->id;
         } else {
             $message->fails = true;
             $message->messages = ['db' => 'Something went wrong saving the data'];
         }
     }
     return json_encode($message);
 }