コード例 #1
0
 public function postMakeSessionCurrent(Request $request)
 {
     $session_id = $request->input('session_id');
     $input = ['session_id' => $session_id];
     $validator = validator::make($request->all(), ['session_id' => 'required']);
     if ($validator->fails()) {
         return ApiResponseClass::errorResponse('You Have Some Input Errors. Please Try Again!!', $input, $validator->errors());
     } else {
         DB::beginTransaction();
         try {
             $school_session = SchoolSession::findOrFail($session_id);
             $current_session = SchoolSession::where('school_id', $this->getSchoolAndUserBasicInfo()->getSchoolId())->where('current_session', 1)->get()->first();
             if ($current_session && $current_session->count() > 0) {
                 $current_session->current_session = 0;
                 if (!$current_session->save()) {
                     throw new ErrorException();
                 }
             }
             $school_session->current_session = 1;
             if (!$school_session->save()) {
                 throw new ErrorException();
             }
             DB::commit();
         } catch (ModelNotFoundException $e) {
             DB::rollback();
             return ApiResponseClass::errorResponse('There is Something Wrong. Please Try Again!!', $input);
         } catch (ErrorException $e) {
             DB::rollback();
             return ApiResponseClass::errorResponse('There is Something Wrong. Please Try Again!!', $input);
         }
         return ApiResponseClass::successResponse($school_session, $input, 'Congratulations. This is Your Current Session Now!!');
     }
     return ApiResponseClass::errorResponse('There is Something Wrong. Please Try Again!!', $input);
 }