Пример #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)]);
 }
Пример #2
0
 /**
  * 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]);
 }
 /**
  * List messages.
  *
  * @return Response
  */
 public function index()
 {
     return view('message.conversation.index', ['messages' => Message::conversations()->user()->with(['sender', 'receiver'])->orderBy('updated_at', 'desc')->paginate(self::DEFAULT_PAGE_SIZE)]);
 }
Пример #4
0
 /**
  * Create a random Message in a conversation.
  *
  * @param VisualAppeal\Connect\MessageConversation $conversation (Default: null, newly created)
  *
  * @return VisualAppeal\Connect\Message
  */
 public function createMessage($conversation)
 {
     $conversation = $conversation ?: $this->createConversation();
     return \VisualAppeal\Connect\Message::create(['message_conversation_id' => $conversation->id, 'from_user_id' => $conversation->from_user_id, 'to_user_id' => $conversation->to_user_id, 'message' => $this->faker->sentence]);
 }