/** * 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]); }
/** * 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]); }