public function therapyAdd(Request $request) { $name = Input::get('tname1'); //Get therapy name $des = Input::get('tdes1'); //Get therapy description //insert new data try { Therapies::create(['name' => $name, 'description' => $des]); //Get the terapy details of newly added therapy $therapy_ob = Therapies::whereName($name)->first(); if (isset(Input::file('profile_img')[0])) { /* This function will upload image */ self::upload_image($request, $therapy_ob->id); /* Updates Database Images table Image_path with new path */ $ther_ob = Therapies::whereName($name)->first(); $ther_ob->image_path = "therapy_images/therapy_img_" . $therapy_ob->id . ".png"; $ther_ob->save(); } $res['error'] = false; return response()->json($res); } catch (Exception $e) { $HTMLView = (string) view('errors.adminError'); $res['page'] = $HTMLView; $res['error'] = true; return response()->json($res); } }