/**
  * Store a newly created ShareUser in storage.
  * POST /shareUsers
  *
  * @param Request $request
  *
  * @return Response
  */
 public function store(Request $request)
 {
     if (sizeof(ShareUser::$rules) > 0) {
         $validator = $this->validateRequestOrFail($request, ShareUser::$rules);
         if ($validator) {
             return $validator;
         }
     }
     $input = $request->all();
     $user = User::where('id', $input['user_id'])->first();
     if ($user) {
         $shared_with_other_account = User::where('phoneNo', $user->phoneNo)->lists('id');
         if (count($shared_with_other_account) > 0) {
             $alreadyShared = ShareUser::where('share_objectId', $input['share_objectId'])->wherein('user_id', $shared_with_other_account)->get();
             if (count($alreadyShared) > 0) {
                 return response()->json("The share object id has already been taken.", 403);
             }
         }
         $shareUsers = $this->shareUserRepository->create($input);
         $shared_user = User::where('objectId', $shareUsers->share_objectId)->first();
         if ($shared_user) {
             $shared_user->points += 10;
             $shared_user->update();
             $user->shared = true;
             $user->update();
             $role = Role::where('userId', $user->objectId)->first();
             if ($role) {
                 $user['role'] = $role->name;
             } else {
                 $user['role'] = 'User';
             }
         }
         return $this->sendResponse($user->toArray(), "ShareUser saved successfully");
     }
 }
Пример #2
0
 public function search($input)
 {
     $query = ShareUser::query();
     $columns = Schema::getColumnListing('shareUsers');
     $attributes = array();
     foreach ($columns as $attribute) {
         if (isset($input[$attribute]) and !empty($input[$attribute])) {
             $query->where($attribute, $input[$attribute]);
             $attributes[$attribute] = $input[$attribute];
         } else {
             $attributes[$attribute] = null;
         }
     }
     return [$query->get(), $attributes];
 }