public function postJoinCourse(Request $request) { if ($request->ajax()) { $input = $request->only(['course_id']); $input['state'] = Participant::PENDING; $input['user_id'] = Auth::id(); Participant::create($input); return response()->json(['id' => $input['course_id']]); } }
public static function notification($template, $recipient, $variables) { $variables['recipient'] = $recipient; if ($recipient instanceof User) { $recipient = array($recipient); } foreach ($recipient as $user) { $messageParts = View::make('messenger.templates.' . $template, $variables)->renderSections(); $thread = Thread::create(['subject' => $messageParts['subject']]); // Message Message::create(['thread_id' => $thread->id, 'user_id' => $user->id, 'body' => $messageParts['body'] . $messageParts['footer'], 'type' => 'notification']); // Sender Participant::create(['thread_id' => $thread->id, 'user_id' => $user->id]); // Recipients $thread->addParticipants(array($user->id)); } }
/** * 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' => strip_tags($input['message'])]); // Sender Participant::create(['thread_id' => $thread->id, 'user_id' => Auth::user()->id, 'last_read' => new Carbon()]); // Recipients if (Input::has('recipients')) { $recipients = array_filter(explode(',', trim($input['recipients']))); $recipientsAllowed = array(); foreach ($recipients as $recipient) { // Until further notice, remove the check to see if the participant is allowed to message each other // if (UserRepository::canMessage($recipient)) { $recipientsAllowed[] = $recipient; // } } $thread->addParticipants($recipientsAllowed); } $participants = $message->thread->participants; foreach ($participants as $participant) { if ($participant->user->id != $message->user->id) { Event::fire('App.Events.NewMessage', [new NewMessage($participant)]); } } return Redirect::to('messages'); }
/** * Run the database seeds. * * @return void */ public function run() { \App\Models\Participant::create(['barcode' => "1", 'name' => 'Ssoele', 'image' => 'ssoele']); }