/**
  * Handle an incoming request.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  \Closure  $next
  * @return mixed
  */
 public function handle($request, Closure $next)
 {
     $user_roll = $request->input('user_roll');
     $user_secret = $request->input('user_secret');
     $user = User::where('user_roll', '=', $user_roll)->where('user_secret', '=', $user_secret)->get();
     if (count($user) > 0) {
         return $next($request);
     }
     return JSONResponse::response(401);
 }
 public function profileGetAllDetails(Request $request)
 {
     $user_roll = $request->input('user_roll');
     $users = User::where('user_roll', '!=', $user_roll)->select('user_id', 'user_roll', 'user_name', 'user_phone', 'user_type')->get();
     foreach ($users as $user) {
         $teams = TeamMember::where('user_id', '=', $user->user_id)->lists('team_id');
         $user->teams = $teams;
     }
     return JSONResponse::response(200, $users);
 }
 public function register(Request $request)
 {
     $user_gcmid = $request->input("user_gcmid");
     $user_roll = $request->input("user_roll");
     $user = User::where('user_roll', '=', $user_roll)->first();
     if ($user == NULL) {
         return JSONResponse::response(400);
     }
     $user->user_gcmid = $user_gcmid;
     $user->save();
     return JSONResponse::response(200, true);
 }
 public function createTaskMessages(Request $request)
 {
     $user_roll = $request->input('user_roll');
     $user_msg = $request->input('user_msg');
     $task_id = $request->input('task_id');
     $user_id = User::where('user_roll', '=', $user_roll)->pluck('user_id');
     $msg = new Msg();
     $msg->user_id = $user_id;
     $msg->task_id = $task_id;
     $msg->msg_data = $user_msg;
     $success = $msg->save();
     if (!$success) {
         return JSONResponse::response(200, false);
     }
     // if success return the msg
     $exported_fields = ["msg.msg_id", "msg.task_id", "users.user_name", "msg.created_at", "msg.msg_data"];
     $saved_msg = Msg::join('users', 'users.user_id', '=', 'msg.user_id')->where('msg_id', '=', $msg->msg_id)->select($exported_fields)->first();
     // Push Notification Code starts here
     $task_user_rolls = Assigned::where('task_id', '=', $task_id)->leftJoin('users', 'assigned.user_id', '=', 'users.user_id')->lists('user_roll');
     $push_message = Push::jsonEncode('message', $saved_msg);
     Push::sendMany($task_user_rolls, $push_message);
     // Push Notification Code ends here
     return JSONResponse::response(200, $saved_msg);
 }
 public function getAssignedForTask(Request $request)
 {
     $task_id = $request->input('task_id');
     $user_list = Assigned::where('task_id', '=', $task_id)->leftJoin('users', 'assigned.user_id', '=', 'users.user_id')->select('users.user_roll', 'users.user_name')->get();
     return JSONResponse::response(200, $user_list);
 }