示例#1
0
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     // 1
     \VisualAppeal\Connect\MessageConversation::create(['from_user_id' => 1, 'to_user_id' => 2]);
     // 1
     \VisualAppeal\Connect\Message::create(['message_conversation_id' => 1, 'from_user_id' => 2, 'to_user_id' => 1, 'message' => "Hi Tim, how are you? Can we talk later?\n\nKind regards Arno", 'read' => 1, 'read_at' => \Carbon\Carbon::now()->subHours(5), 'created_at' => \Carbon\Carbon::now()->subHours(6), 'updated_at' => \Carbon\Carbon::now()->subHours(5)]);
     // 2
     \VisualAppeal\Connect\Message::create(['message_conversation_id' => 1, 'from_user_id' => 1, 'to_user_id' => 2, 'message' => "Hi Arno,\nThat would be great. Just call me on my smartphone!", 'read' => 1, 'read_at' => \Carbon\Carbon::now()->subHours(4), 'created_at' => \Carbon\Carbon::now()->subHours(5), 'updated_at' => \Carbon\Carbon::now()->subHours(4)]);
     // 3
     \VisualAppeal\Connect\Message::create(['message_conversation_id' => 1, 'from_user_id' => 2, 'to_user_id' => 1, 'message' => "Ok I will call you on your new number.", 'created_at' => \Carbon\Carbon::now()->subHours(4)]);
 }
 /**
  * Saves a new conversation in the database.
  *
  * @param Request $request
  *
  * @return Response
  */
 public function store(Request $request)
 {
     $this->validate($request, $this->createMessageRules);
     // Check if conversation already exists
     $conversation = MessageConversation::where('from_user_id', '=', \Sentry::getUser()->id)->where('to_user_id', '=', $request->input('to_user_id'))->first();
     if (!isset($conversation)) {
         $conversation = MessageConversation::create(['from_user_id' => \Sentry::getUser()->id, 'to_user_id' => $request->input('to_user_id')]);
     }
     if (!isset($conversation)) {
         abort(503);
     }
     return redirect()->route('conversation.show', ['conversation' => $conversation->id]);
 }
 /**
  * Validate the input and store the message in the database.
  *
  * @param \Illuminate\Http\Request $request
  * @param int $conversationId
  *
  * @return Response
  */
 public function store(Request $request, $conversationId)
 {
     $conversation = MessageConversation::findOrFail($conversationId);
     if ($conversation->from_user_id != \Sentry::getUser()->id && $conversation->to_user_id != \Sentry::getUser()->id) {
         abort(403);
     }
     $this->validate($request, $this->createMessageRules);
     $toUserId = $conversation->from_user_id == \Sentry::getUser()->id ? $conversation->to_user_id : $conversation->from_user_id;
     $message = Message::create(['message_conversation_id' => $conversationId, 'from_user_id' => \Sentry::getUser()->id, 'to_user_id' => $toUserId, 'message' => $request->input('message')]);
     if (!isset($message)) {
         abort(503);
     }
     $conversation->touch();
     return redirect()->route('conversation.show', ['conversation' => $message->message_conversation_id, '#message-' . $message->id]);
 }
示例#4
0
 /**
  * Create a conversation between two users.
  *
  * @param VisualAppeal\Connect\User $user1 (Default: null, newly created)
  * @param VisualAppeal\Connect\User $user2 (Default: null, newly created)
  *
  * @return VisualAppeal\Connect\MessageConversation
  */
 public function createConversation($user1 = null, $user2 = null)
 {
     $user1 = $user1 ?: $this->createUser();
     $user2 = $user2 ?: $this->createUser();
     return \VisualAppeal\Connect\MessageConversation::create(['from_user_id' => $user1->id, 'to_user_id' => $user2->id]);
 }