Пример #1
0
 /**
  * Store a newly created resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @return \Illuminate\Http\Response
  */
 public function store(Request $request)
 {
     $data = $request->all();
     $offenderData = isset($data['offender'][0]) ? $data['offender'][0] : null;
     $offenderFields = Schema::connection('mysql')->getColumnListing('offenders');
     if (isset($offenderData)) {
         $offender = new Offender();
         foreach ($offenderData as $field) {
             if (in_array($field['name'], $offenderFields)) {
                 if ($this->utilityService->isDateField($field['name'])) {
                     $field['value'] = $this->utilityService->parseToMysqlDate($field['value']);
                 }
                 $offender[$field['name']] = $field['value'];
             }
         }
         $offender->save();
         if (isset($data['cases'])) {
             foreach ($data['cases'] as $newCase) {
                 $offender->rjCases()->attach($newCase);
             }
         }
     }
     return response()->json(array('success' => 'true', 'id' => $offender->id));
 }
Пример #2
0
 /**
  * Store a newly created resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @return \Illuminate\Http\Response
  */
 public function store(Request $request)
 {
     $data = $request->all();
     $caseFields = Schema::connection('mysql')->getColumnListing('rj_cases');
     if (isset($data['case'][0])) {
         $case = new RjCase();
         foreach ($data['case'][0] as $field) {
             if (in_array($field['name'], $caseFields)) {
                 if ($this->utilityService->isDateField($field['name'])) {
                     $field['value'] = $this->utilityService->parseToMysqlDate($field['value']);
                 }
                 $case[$field['name']] = $field['value'];
             }
         }
         $case->save();
     }
     if (isset($data['victim'])) {
         $victimFields = Schema::connection('mysql')->getColumnListing('victims');
         foreach ($data['victim'] as $newVictim) {
             $victim = new Victim();
             foreach ($newVictim as $key => $value) {
                 if (in_array($key, $victimFields)) {
                     if ($this->utilityService->isDateField($key)) {
                         $value['value'] = $this->utilityService->parseToMysqlDate($value['value']);
                     }
                     $victim[$key] = $value['value'];
                 }
             }
             $victim->save();
             $case->victims()->attach($victim->id);
         }
     }
     if (isset($data['offender'])) {
         $offenderFields = Schema::connection('mysql')->getColumnListing('offenders');
         foreach ($data['offender'] as $newOffender) {
             $offender = new Offender();
             foreach ($newOffender as $key => $value) {
                 if (in_array($key, $offenderFields)) {
                     if ($this->utilityService->isDateField($key)) {
                         $value['value'] = $this->utilityService->parseToMysqlDate($value['value']);
                     }
                     $offender[$key] = $value['value'];
                 }
             }
             $offender->save();
             $case->offenders()->attach($offender->id);
         }
     }
     if (isset($data['charge'])) {
         foreach ($data['charge'] as $newCharge) {
             $case->charges()->attach($newCharge);
         }
     }
     if (isset($data['facilitator'])) {
         foreach ($data['facilitator'] as $newFacilitator) {
             $case->users()->attach($newFacilitator);
         }
     }
     return array('status' => 'success', 'id' => $case->id);
 }