public function update($id)
 {
     try {
         $thread = Thread::findOrFail($id);
     } catch (ModelNotFoundException $e) {
         Session::flash('error_message', 'The thread with ID: ' . $id . ' was not found.');
         return redirect('messages');
     }
     $message = Message::create(['thread_id' => $thread->id, 'user_id' => Auth::user()->id, 'body' => Input::get('message')]);
     $participant = Participant::firstOrCreate(['thread_id' => $thread->id, 'user_id' => Auth::user()->id]);
     $participant->last_read = new Carbon();
     $participant->save();
     return redirect('/message/' . $id);
 }
示例#2
0
文件: Thread.php 项目: blrik/bWorks
 public function addParticipants($participants, $id)
 {
     Participant::firstOrCreate(['user_id' => $participants, 'thread_id' => $id]);
 }
示例#3
0
 public function updateMessage(Request $request, $slug)
 {
     $this->validate($request, ['body' => 'required']);
     $update = Thread::where('slug', $slug)->first();
     $participant = Participant::where('thread_id', $update->id)->where('user_id', $request->user()->id)->first();
     if ($update && $participant) {
         $update->activateAllParticipants();
         $message = new Message();
         $message->thread_id = $update->id;
         $message->user_id = $request->user()->id;
         $message->body = $request->get('body');
         $message->save();
         $participant = Participant::firstOrCreate(['thread_id' => $update->id, 'user_id' => $request->user()->id]);
         $participant->last_read = new Carbon();
         $participant->save();
         return redirect()->back()->withMessage('Сообщение отправлено.');
     } else {
         return redirect()->route('messages')->withError('Ошибка, свяжитесь с администратором.');
     }
 }