public function updateUserProfile(Request $request) { try { $display_image = $request->file('display_image'); $inputs = $request->all(); $data = []; foreach ($inputs as $key => $value) { if ($key == 'orignal_image') { continue; } $data[$key] = $value; } if ($display_image) { //Upload Image $uploaded_path = FileUpload::upload($display_image); $data['display_image'] = $uploaded_path; //Dummy } else { $data['display_image'] = $inputs['orignal_image']; } User::where('id', $inputs['id'])->update($data); return Redirect::to('/crm/profile')->withMessage(Generate::success_message('Success', 'Profile Updated.')); } catch (Exception $e) { return Redirect::to('/crm/profile')->withMessage(Generate::error_message('Fail', 'Failed to update.')); } }
/** * Store a newly created resource in storage. * * @param \Illuminate\Http\Request $request * @return \Illuminate\Http\Response */ public function store(CreatePostRequest $request) { try { $inputs = $request->all(); unset($inputs['_token']); $photo = $request->file('photo'); if ($photo) { //Upload Image $uploaded_path = FileUpload::upload($photo); $inputs['photo'] = $uploaded_path; } Post::create($inputs); return redirect()->to('/crm/post/')->withMessage(Generate::success_message('Success', 'Created Successfully')); } catch (Exception $e) { return redirect()->to('/crm/post/')->withMessage(Generate::error_message('Failed', $e->getMessage())); } }
public function newPost(Request $request) { try { $session_token = $request->get('session_token'); $customer = SessionUtil::getCustomer($session_token); $description = $request->get('description'); $photo = $request->file('photo'); $inputs = []; if ($photo) { //Upload Image $uploaded_path = FileUpload::upload($photo); $inputs['photo'] = $uploaded_path; } $inputs['description'] = $description; $inputs['customer_id'] = $customer->id; Post::create($inputs); return Response::json(['status' => 1, 'message' => 'Success']); } catch (Exception $e) { return Response::json(['status' => 0, 'message' => $e->getMessage()]); } }
/** * Update the specified resource in storage. * * @param \Illuminate\Http\Request $request * @param int $id * @return \Illuminate\Http\Response */ public function update(UpdateUserFormRequest $request, $id) { try { $inputs = $request->all(); $display_image = $request->file('display_image'); $user = User::find($id); $user->email = $inputs['email']; $user->country = $inputs['country']; $user->display_name = $inputs['display_name']; $user->language = $inputs['language']; $user->activation_status = $inputs['activation_status']; $user->about_me = $inputs['about_me']; $user->role_id = $inputs['role_id'] ? $inputs['role_id'] : null; if ($display_image) { //Upload Image $uploaded_path = FileUpload::upload($display_image); $user->display_image = $uploaded_path; } $save = $user->save(); return Redirect::to('/crm/user/' . $id)->withMessage(Generate::success_message('Success', 'User Details Updated')); } catch (Exception $e) { return Redirect::to('/crm/user/' . $id)->withMessage(Generate::error_message('Failed', $e->getMessage())); } }