/**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     for ($i = 0; $i < 10; $i++) {
         $p = new Participant();
         $p->first_name = 'random ' . rand();
         $p->last_name = 'randomgen';
         $p->sex = rand() % 2 ? 'm' : 'f';
         $p->save();
     }
 }
Example #2
0
 /**
  * Update the specified resource in storage.
  *
  * @param  int  $id
  * @return Response
  */
 public function update(Request $request, $id)
 {
     //TODO high security mode
     $room = Room::findOrFail($id);
     if (!roomController::checkOwner($room)) {
         throw new Exception('Unauthorized');
     }
     //make validations
     $validator = Validator::make($request->all(), ['name' => 'required', 'email' => 'array']);
     $validator->each('email', ['email']);
     if ($validator->fails()) {
         return redirect('room/edit/' . $id)->withErrors($validator)->withInput()->with('validation_err', true);
     }
     $room->name = $request->input('name');
     $room->recording = empty($request->input('recording')) ? 0 : 1;
     $room->public = empty($request->input('public')) ? 0 : 1;
     $room->save();
     //we save the participants
     $emails = $request->input('email');
     $moderators = $request->input('moderator');
     if (!$moderators) {
         $moderators = array();
     }
     //delete old participants before adding new
     $room->participants()->delete();
     if (is_array($emails)) {
         foreach ($emails as $email) {
             $participant = new Participant();
             $participant->mail = $email;
             $participant->room_id = $room->id;
             if (in_array($email, $moderators)) {
                 $participant->moderator = 1;
             }
             $participant->save();
         }
     }
     return Redirect::action('roomController@show', $room->id);
 }
Example #3
0
 public function friendsSaveMessage(Request $request, $id)
 {
     $this->validate($request, ['name' => 'required|min:2', 'body' => 'required']);
     $user = User::where('id', $request->user()->id)->first();
     $friends = User::where('id', $id)->first();
     if ($user && $friends) {
         if (!$user->isFriendsWith($friends) || $user->id == $friends->id) {
             return redirect()->route('home')->withError('Ошибка, свяжитесь с администратором.');
         }
         $thread = new Thread();
         $thread->user_id = $user->id;
         $thread->name = $request->get('name');
         $thread->slug = md5($thread->user_id . '_' . $thread->name . new Carbon());
         $thread->save();
         $thread->addParticipants($friends->id, $thread->id);
         $message = new Message();
         $message->thread_id = $thread->id;
         $message->user_id = $user->id;
         $message->body = $request->get('body');
         $message->save();
         $participant = new Participant();
         $participant->thread_id = $thread->id;
         $participant->user_id = $user->id;
         $participant->last_read = new Carbon();
         $participant->save();
         return redirect()->route('messages')->withMessage('Сообщение отправлено.');
     } else {
         return redirect()->route('messages')->withError('Ошибка, свяжитесь с администратором.');
     }
 }