/** * @param Request $request * @return mixed */ public function incomingAppointmentRequest(Request $request) { $inboundRequest = $request->all(); $body = $inboundRequest['Body']; $from_phone = $inboundRequest['From']; $appointmentMessage = Appointment_Message::find($body); if (!$appointmentMessage) { return response()->view('admin.messaging.responses.wrong_code')->header('Content-Type', 'text/xml'); } $agent = Agents::where('mobile_phone', $from_phone)->with('messages')->first(); $agent->messages()->attach($appointmentMessage->id); $zipcode = $appointmentMessage->zipcode; // No message exists, tell the user the wrong code was entered //Other wise, give the user feedback, fire an event and return xml to the user if ($appointmentMessage->responses == 0) { $appointmentMessage->responses = 1; $appointmentMessage->agent_id = $agent->id; $appointmentMessage->save(); //event(new AppointmentWasAssigned($agent)); return response()->view('admin.messaging.responses.lead_accepted', compact('zipcode', 'from_phone'))->header('Content-Type', 'text/xml'); } // Always assume failure and return the response return response()->view('admin.messaging.responses.lead_was_taken')->header('Content-Type', 'text/xml'); }