public function conversation(Request $request, $id)
 {
     $conversation = Message::findOrFail($id);
     $user = Auth::user();
     if (Auth::user()->is('agent')) {
         if ($user->id != $conversation->recipient_id) {
             abort(403, 'Unauthorized action.');
         }
     } elseif (Auth::user()->is('administrator')) {
     }
     if ($request->isMethod('POST')) {
         $rules = ['message' => 'required'];
         $this->validate($request, $rules);
         $message = new Message(['message' => $request->input('message')]);
         $message->sender()->associate($user);
         $message->recipient()->associate($conversation->sender);
         $message->referenced()->associate($conversation->referenced);
         $message->parentMessage()->associate($conversation);
         $message->save();
         return redirect()->back()->with('success', ['Message is successfully sent.']);
     }
     return view('admin.customer_inquiry.conversation', ['conversation' => $conversation]);
 }
Esempio n. 2
0
 public function postSendMessage(Request $request, $property_id = NULL)
 {
     $rules = ['message' => 'required'];
     $this->validate($request, $rules);
     $property = Property::find($property_id);
     $property->load('agentList');
     $user = Auth::user();
     if ($property->agentList) {
         $agent = $property->agentList;
     } else {
         $agent = ProjectHelper::getDefaultAgent();
     }
     $conversation = $user->getPropertyConversation($property);
     if ($conversation) {
         $agent = $conversation->recipient;
     } else {
         $conversation = $user->createPropertyConversation($property, $agent);
     }
     $message = new Message(['message' => $request->input('message')]);
     $message->sender()->associate($user);
     if ($agent) {
         $message->recipient()->associate($agent);
     }
     $message->referenced()->associate($property);
     $message->parentMessage()->associate($conversation);
     $message->save();
     if ($request->ajax()) {
         $return = ['message' => ['id' => $message->id, 'text' => $message->message]];
         return response()->json($return);
     }
     return redirect()->back()->with('messages', [trans('property.inbox.sent_message')]);
 }
Esempio n. 3
0
 public function createPropertyConversation($property, $agent = NULL)
 {
     if (!$property->relationLoaded('agentList')) {
         $property->load('agentList');
     }
     if (!$agent) {
         if ($property->agentList) {
             $agent = $property->agentList;
         }
     }
     //Create new conversation
     $conversation = new Message();
     if ($property->user_id == $this->id) {
         $conversation->type = Message::TYPE_OWNER_MESSAGE;
     } else {
         $conversation->type = Message::TYPE_USER_MESSAGE;
     }
     $conversation->sender()->associate($this);
     $conversation->referenced()->associate($property);
     if ($agent) {
         $conversation->recipient()->associate($agent);
     }
     $conversation->save();
     return $conversation;
 }