public function read() { $thread = Thread::find($this->request->get('id')); if (!$thread) { return return_rest('0', compact('count'), '该消息不存在'); } $thread->markAsRead($this->user()->id); return return_rest('1', compact('count'), '已读消息'); }
/** * Mark a specific thread as read, for ajax use * * @param $id */ public function read($id) { $thread = Thread::find($id); if (!$thread) { abort(404); } $thread->markAsRead(Auth::id()); }
/** * Delete a message */ public function delete($id) { try { $message = Message::findOrFail($id); } catch (ModelNotFoundException $e) { Session::flash('error_message', 'The message with ID: ' . $id . ' was not found.'); return redirect('messages'); } if (Auth::user()->id == $message->user_id || Auth::user()->isAdmin()) { // get thread ID and check if this was the last remaining message in the thread! // then we have to delete the thread as well!!! $thread_id = $message->thread_id; $message->delete(); Session::flash('error_message', 'Message deleted.'); $msgs = Message::where('thread_id', $thread_id)->get(); if (count($msgs) == 0) { $thread = Thread::find($thread_id)->delete(); return redirect('messages'); } } else { Session::flash('error_message', 'You can only delete your own messages.'); return redirect('messages'); } return redirect()->back(); }
/** * Send Email notification of new internal messages * * @param Message $message */ function sendEmailNotification(Message $message) { $subject = 'c-SPOT internal message notification'; $thread = Thread::find($message->thread_id); $thread_subject = $thread->subject; $message_body = $message->body; foreach ($thread->participants as $key => $recipient) { $user = $recipient->user; # check if user actually wants to be notified if ($user->notify_by_email) { Mail::send('cspot.emails.notification', ['user' => $user, 'subject' => $subject, 'messi' => $message], function ($msg) use($user, $subject) { $msg->from(findAdmins()[0]->email, 'c-SPOT Admin'); $msg->to($user->email, $user->fullName); $msg->subject($subject); }); } } }