public function searchOffenders($searchType, $searchStr) { $offenders = Offender::where($searchType, 'LIKE', $searchStr)->get(); if ($offenders) { return $offenders; } return null; }
/** * Update the specified resource in storage. * * @param \Illuminate\Http\Request $request * @param int $id * @return \Illuminate\Http\Response */ public function update(Request $request) { $data = $request->all(); $caseFields = Schema::connection('mysql')->getColumnListing('rj_cases'); if (isset($data)) { $case = RjCase::find($data['id']); foreach ($data as $key => $value) { if (in_array($key, $caseFields)) { if ($this->utilityService->isDateField($key)) { $value = !empty($value) ? $this->utilityService->parseToMysqlDate($value) : null; } $case[$key] = $value; } } $case->save(); } if (isset($data['victims'])) { $victimFields = Schema::connection('mysql')->getColumnListing('victims'); foreach ($data['victims'] as $newVictim) { $victim = Victim::find($newVictim['id']); foreach ($newVictim as $key => $value) { if (in_array($key, $victimFields)) { if ($this->utilityService->isDateField($key)) { $value = $this->utilityService->parseToMysqlDate($value); } $victim[$key] = $value; } } $victim->save(); } } if (isset($data['offenders'])) { $offenderFields = Schema::connection('mysql')->getColumnListing('offenders'); foreach ($data['offenders'] as $newOffender) { $offender = Offender::find($newOffender['id']); foreach ($newOffender as $key => $value) { if (in_array($key, $offenderFields)) { if ($this->utilityService->isDateField($key)) { $value = $this->utilityService->parseToMysqlDate($value); } $offender[$key] = $value; } } $offender->save(); } } if (isset($data['charges'])) { $existingCharges = RjCase::find($data['id'])->charges; foreach ($data['charges'] as $newCharge) { if (!in_array($newCharge, $existingCharges->toArray())) { $case->charges()->detach(); } } foreach ($data['charges'] as $newCharge) { $case->charges()->attach($newCharge); } } if (isset($data['facilitators'])) { $existingFacilitators = RjCase::find($data['id'])->users; foreach ($data['facilitators'] as $newFacilitator) { if (!in_array($newFacilitator, $existingFacilitators->toArray())) { $case->users()->detach(); } } foreach ($data['facilitators'] as $newFacilitator) { $case->users()->attach($newFacilitator); } } return response()->json(array('id' => $case->id)); }
public function checkIfExists(Request $request) { $data = $request->all(); if (Offender::where('offenderId', '=', $data['offenderId'])->exists()) { return "false"; } return "true"; }