public function newPatient() { $input = Input::all(); if (!is_numeric($input['address'])) { $input['address'] = DB::table('address')->insertGetId(array('address' => $input['address'])); } $patient = DB::table('patients')->where('full_name', $input['fullName'])->where('address', $input['address'])->first(); // if (! Until::isNull($patient) && ! Input::has('patientId') ) { // if (! Input::has('ok')){ // return 'false'; // } // } $fullName = $input['fullName']; $ary = explode(" ", $fullName); $pop = array_pop($ary); $patient = new Patient(); if (Input::has('patientId') && !Until::isNull($input['patientId'])) { $patient = Patient::where('id', $input['patientId'])->first(); } else { $temp = Patient::orderBy('id', 'desc')->first(); $pat_id = 1; if (!Until::isNull($temp)) { $pat_id += $temp->id; } $patient->patient_id = Until::convertIntToString($pat_id); } $patient->first_name = implode(" ", $ary) . ' '; $patient->last_name = $pop; $patient->full_name = $input['fullName']; $patient->age = $input['age']; $patient->is_month = false; if (Input::has('isMonth')) { $patient->is_month = true; } $patient->weight = $input['weight']; $patient->address = $input['address']; $patient->relatives = $input['parent']; $patient->phone = $input['phone']; $patient->save(); return Response::json(array('id' => $patient->id)); }