/** * Stores a new message thread * * @return mixed */ public function store() { $input = Input::all(); $thread = Thread::create( [ 'subject' => $input['subject'], ] ); // Message Message::create( [ 'thread_id' => $thread->id, 'user_id' => $this->user->id, 'body' => $input['message'], ] ); // Sender Participant::create( [ 'thread_id' => $thread->id, 'user_id' => $this->user->id, 'last_read' => new Carbon ] ); // Recipients if (Input::has('recipients')) { $thread->addParticipants($input['recipients']); } return Redirect::to('messages')->with('message', 'сообщение сохраненно'); }
/** * Stores a new message thread * * @return mixed */ public function store() { $input = Input::all(); $thread = Thread::create(['subject' => $input['subject']]); // Message Message::create(['thread_id' => $thread->id, 'user_id' => Auth::user()->id, 'body' => $input['message']]); // Sender Participant::create(['thread_id' => $thread->id, 'user_id' => Auth::user()->id, 'last_read' => new Carbon()]); // Recipients if (Input::has('recipients')) { $thread->addParticipants($input['recipients']); } return redirect('messages'); }
public function store(Request $request) { $input = $request->all(); $thread = Thread::create(['subject' => $input['subject']]); // Message Message::create(['thread_id' => $thread->id, 'user_id' => Sentinel::getUser()->id, 'body' => $input['message']]); // Sender Participant::create(['thread_id' => $thread->id, 'user_id' => Sentinel::getUser()->id, 'last_read' => new Carbon()]); // Recipients if ($request->has('recipients')) { $thread->addParticipants($input['recipients']); } return redirect('messages'); }
/** * 存储提醒消息 */ public function store() { //推送内容 $subject = $this->request->get('subject'); $thread = Thread::create(['subject' => $subject]); //生成message $message = Message::create(['thread_id' => $thread->id, 'user_id' => $this->user()->id, 'body' => $this->request->get('message')]); // Sender Participant::create(['thread_id' => $thread->id, 'user_id' => $this->user()->id]); // Recipients if ($this->request->has('recipients')) { $thread->addParticipants($this->request->get('recipients')); } return return_rest('1', '', '消息添加成功'); }
/** * Stores a new message thread. * * @return mixed */ public function store() { $input = Input::all(); $thread = Thread::create(['subject' => $input['subject']]); // Message $message = Message::create(['thread_id' => $thread->id, 'user_id' => Auth::user()->id, 'body' => $input['message']]); // Sender Participant::create(['thread_id' => $thread->id, 'user_id' => Auth::user()->id, 'last_read' => new Carbon()]); // Recipients if (Input::has('recipients')) { $thread->addParticipants($input['recipients']); } // email notification via helper method sendEmailNotification($message); return redirect('messages'); }
/** * Shows a message thread. * * @param $id * @return mixed */ public function user($id) { if (Auth::id() != $id) { $user = User::find($id); $thread = Thread::between([Auth::id(), $id])->first(); if ($thread == null) { $thread = Thread::create(['subject' => "Thread between 2 users"]); Participant::create(['thread_id' => $thread->id, 'user_id' => Auth::user()->id, 'last_read' => new Carbon()]); $thread->addParticipants([$id]); } $thread->markAsRead(Auth::id()); return view('messenger.show', compact('thread', 'id', 'user')); } else { return redirect('messages'); } }
/** * Run the database seeds. * * @return void */ public function run() { $faker = Faker\Factory::create(); $faker = Faker\Factory::create(); $slugify = Slugify::create(); $users = User::all(); // Create message threads for all users foreach ($users as $user) { for ($x = rand(2, 4); $x < 5; $x++) { $thread = Thread::create(['subject' => $faker->sentence()]); // Message Message::create(['thread_id' => $thread->id, 'user_id' => $user->id, 'body' => implode($faker->paragraphs())]); // Sender Participant::create(['thread_id' => $thread->id, 'user_id' => $user->id]); // Recipients if (Input::has('recipients')) { for ($i = rand(3, 4); $i < 5; $i++) { $participant = array_rand($users->toArray()); $thread->addParticipants($users[$participant]->id); } } // Create thread replies for ($k = rand(2, 5); $k < 5; $k++) { $thread->activateAllParticipants(); $randUser = array_rand($users->toArray()); // Message Message::create(['thread_id' => $thread->id, 'user_id' => $users[$randUser]->id, 'body' => implode($faker->paragraphs())]); // Add replier as a participant $participant = Participant::firstOrCreate(['thread_id' => $thread->id, 'user_id' => $users[$randUser]->id]); //$participant->last_read = new Carbon; $participant->save(); // Recipients if (Input::has('recipients')) { $thread->addParticipants($user->id); } } if ($thread->getLatestMessageAttribute()->user->id == $user->id) { $thread->markAsRead($user->id); } } } }
/** * Store a newly created resource in storage. * POST /api/{resource}. * * @return Response */ public function store() { $data = $this->request->json()->get($this->resourceKeySingular); if (!$data) { return $this->errorWrongArgs('Empty data'); } $data['user_id'] = Authorizer::getResourceOwnerId(); $validator = Validator::make($data, $this->rulesForCreate()); if ($validator->fails()) { return $this->errorWrongArgs($validator->messages()); } $this->unguardIfNeeded(); $item = $this->model->create($data); /* Assignment_Transaction::create([ ]);*/ $thread = Thread::create(['subject' => 'user-' . $item->id]); Participant::create(['thread_id' => $thread->id, 'user_id' => Authorizer::getResourceOwnerId(), 'last_read' => new Carbon()]); $thread->addParticipants([18]); return $this->respondWithItem($item); }
public function sendMessage() { $input = Input::all(); $thread = Thread::create(['subject' => $input['subject']]); // Message Message::create(['thread_id' => $thread->id, 'user_id' => Auth::user()->id, 'body' => $input['message']]); // Sender Participant::create(['thread_id' => $thread->id, 'user_id' => Auth::user()->id, 'last_read' => new Carbon()]); // Recipients if (Input::has('users')) { $users = $input['users']; // got the users by email $recipients = explode(',', $users); $userIDs = DB::table('users')->whereIn('email', $recipients)->select('id')->get(); $threadParticipants = array(); foreach ($userIDs as $userID) { array_push($threadParticipants, $userID->id); } $thread->addParticipants($threadParticipants); } return view('messages.create', ['page' => 'message', 'users' => $users]); }
/** * Stores a new message thread * * @return mixed */ public function store() { $input = Input::all(); $array = $input['recipients']; $user = null; if (!is_numeric($array[0])) { try { $user = User::where('name', $array[0])->firstOrFail(); } catch (ModelNotFoundException $e) { return Redirect::back()->withErrors(['User does not exist']); } $array[0] = $user->id; $input['recipients'] = $array; } if ($user == null) { try { $user = User::findOrFail($array[0]); } catch (ModelNotFoundException $e) { return Redirect::back()->withErrors(['User does not exist']); } } Mail::send('emails.message', ['user' => $user, 'sender' => Auth::user()->name, 'body' => $input['message'], 'subject' => $input['subject']], function ($m) use($user) { $m->to($user->email, $user->name)->from('*****@*****.**')->subject('You Have A New Message On FishArk!'); }); $thread = Thread::create(['subject' => $input['subject']]); // Message $message = Message::create(['thread_id' => $thread->id, 'user_id' => Auth::user()->id, 'body' => $input['message']]); // Sender Participant::create(['thread_id' => $thread->id, 'user_id' => Auth::user()->id, 'last_read' => new Carbon()]); // Recipients if (Input::has('recipients')) { $thread->addParticipants($input['recipients']); } $this->oooPushIt($message); return redirect('messages'); }
public function createNewThread() { if (Thread::where('subject', Input::get('subject'))->first() == null) { $thread = Thread::create(['subject' => Input::get('subject')]); Participant::create(['thread_id' => $thread->id, 'user_id' => Authorizer::getResourceOwnerId(), 'last_read' => new Carbon()]); $thread->addParticipants([Input::get('participant_id')]); return $thread; } return Thread::where('subject', Input::get('subject'))->first()->get(); }
/** * send message via internal messenger * @param string $subject * @param string $message * @param string $recipient user_id * @param bool $email send email or not */ function sendInternalMessage($subject, $message, $recipient_id, $email = true) { $thread = Thread::create(['subject' => $subject]); // Message $message = Message::create(['thread_id' => $thread->id, 'user_id' => Auth::user()->id, 'body' => $message]); // Sender Participant::create(['thread_id' => $thread->id, 'user_id' => Auth::user()->id, 'last_read' => new Carbon()]); // Add Recipients $thread->addParticipant([$recipient_id]); if ($email) { sendEmailNotification($message); } return $thread->id; }
/** * Stores a new message thread. * * @return mixed */ public function store(\Illuminate\Http\Request $request) { $input = Input::all(); $this->validate($request, ['subject' => 'required|max:255', 'message' => 'required', 'recipients' => 'required']); $thread = Thread::create(['subject' => $input['subject']]); // Message Message::create(['thread_id' => $thread->id, 'user_id' => Auth::user()->id, 'body' => $input['message']]); // Sender Participant::create(['thread_id' => $thread->id, 'user_id' => Auth::user()->id, 'last_read' => new Carbon()]); // Recipients if (Input::has('recipients')) { $thread->addParticipants($input['recipients']); } return redirect('messages'); }
/** * Persists a message to the database * @param MessagesCreateRequest $request * @return \Illuminate\Http\RedirectResponse */ public function store(MessagesCreateRequest $request) { $input = $request; $innovation = Innovation::findOrFail($input['innovation_id']); $thread = Thread::create(['subject' => $input['subject'], 'innovation_id' => $input['innovation_id'], 'user_id' => \Auth::user()->id, 'receiver_id' => $innovation->user_id, 'unique_id' => str_random(30)]); $this->addReceiver($thread, $input['recipients']); // Message $message = Message::create(['thread_id' => $thread->id, 'user_id' => Auth::user()->id, 'body' => $input['message'], 'starter_id' => \Auth::user()->id, 'innovation_id' => $input['innovation_id']]); if (Input::has('progress')) { Progress::create(['innovation_id' => $input['innovation_id'], 'investor_id' => Auth::user()->id, 'progress_status' => 1]); } // Sender Participant::create(['thread_id' => $thread->id, 'user_id' => Auth::user()->id, 'last_read' => new Carbon()]); // Recipients if (Input::has('recipients')) { $thread->addParticipants($input['recipients']); } $this->oooPushIt($message); return redirect('innovation/' . $innovation->id . '#messages'); }
/** * Stores a new message thread * * Example URL: POST /api/v1/messages?api_key=30ce6864e2589b01bc002b03aa6a7923 * * @return mixed */ public function store() { $userId = $this->user->id; // @todo: run validation $input = Input::all(); $thread = Thread::create(['subject' => $input['subject']]); // Message Message::create(['thread_id' => $thread->id, 'user_id' => $userId, 'body' => $input['message']]); // Sender Participant::create(['thread_id' => $thread->id, 'user_id' => $userId, 'last_read' => new Carbon()]); // Recipients if (Input::has('recipients')) { $thread->addParticipants($input['recipients']); } return $this->respondWithCreated(['id' => $thread->id]); }