public function store() { $temp = Category_lv2::getItemInfor(Input::get("category_id2")); $category_id = $temp["parent_id"]; $user = Session::get('user_info'); $user_id = $user['user_id']; $post_count = $user['post_count'] + 1; $target_file = ImageController::uploadImage("image"); if (Session::has("imageMessage")) { echo Session::get("imageMessage"); } $array = array('category_id' => $category_id, 'category_id2' => Input::get("category_id2"), 'user_id' => $user_id, 'title' => Input::get("title"), 'price' => Input::get("price"), 'description' => Input::get("description"), 'image' => $target_file, 'phone' => Input::get("phone"), 'priority' => Input::get("priority"), 'address' => Input::get("address"), 'location' => Input::get("location")); //store to database if ($this->model->makePost($array)) { Users::updateUserInfor($user_id, array("post_count" => $post_count)); return Redirect::to('member/post/create'); } else { echo "Error"; } }
public function postEditProfile() { $editMessage = ""; $imageFilePath = ImageController::uploadImage("avatar"); $rules = array("full_name" => "required|min:3|max:32", "phone" => "numeric|min:11"); if (Validator::make(Input::all(), $rules)->fails()) { $editMessage = "Validate false"; Session::put("editMessage", $editMessage); return $editMessage; } $arrayUpdate = array('full_name' => Input::get("full_name"), 'phone' => Input::get("phone"), 'address' => Input::get("address"), 'avatar' => $imageFilePath); if ($this->model->updateUserInfor(Input::get("user_id"), $arrayUpdate)) { $userInfor = Users::getInformation(['param1' => 'user_id', 'param2' => Input::get("user_id")]); Session::put("user_info", $userInfor); return Redirect::to("member/edit-profile"); } else { $editMessage = "Update database error!"; Session::put("editMessage", $editMessage); return $editMessage; } }
/** * This method update and save all the changes into the profile's user * and return to the user's profile page * @param Request $request * @return $this|\Illuminate\Http\RedirectResponse */ public function postUpdateProfile(Request $request) { $validator = Validator::make($request->only(['name']), ['name' => 'required']); if ($validator->fails()) { return back()->withInput()->withErrors($validator); } //Find the user if exist before update $user = User::findOrFail(Auth::user()->id); $user->categories()->detach(); if ($request->input('categories') && is_array($request->input('categories'))) { $user->categories()->attach($request->input('categories')); } //dd($request->all()); try { //If has file if ($request->hasFile('profilePicture') && $request->file('profilePicture')->isValid()) { //validate if the uploaded file is an image $validator = Validator::make($request->only(['profilePicture']), ['profilePicture' => 'image']); if ($validator->fails()) { return back()->withInput()->withErrors($validator); } //save temp file $filename = Storage::putFile('public/profiles', Input::file('profilePicture')); //resize to 200px $image = Image::make(storage_path() . '/app/' . $filename)->orientate(); $image = $image->fit(200); //delete the temp file ImageController::delete($filename); //save the new user file $filename = str_random(10) . '.jpg'; ImageController::save('/profiles/' . $filename, $image->stream('jpg', 70)); //Delete the old image if ($user->profileImage && ImageController::exist('profiles/' . $user->profileImage)) { ImageController::delete('profiles/' . $user->profileImage); } } } catch (\Exception $error) { Log::error($error->getMessage()); return back()->withInput()->withErrors(array('message' => trans('app.Error505'))); } //Save the user data $user->name = $request->input('name', $user->name); $user->aboutMe = $request->input('aboutMe', $user->aboutMe); $user->country = $request->input('country', $user->country); $user->state = $request->input('state', $user->state); $user->city = $request->input('city', $user->city); $user->city2 = $request->input('city2', $user->city); $user->birthday = empty($request->input('birthday')) ? null : $request->input('birthday'); $user->profileImage = isset($filename) ? $filename : $user->profileImage; $user->save(); $request->session()->flash('flash-success', trans('app.ProfileSaveSuccess')); return redirect()->route('getUserProfile', ['name' => str_slug($user->name), 'id' => $user->id]); }
private function saveImage($request) { if (!is_null($request->file('image'))) { $imageController = new ImageController(); $imageController->setDestination("images"); $imageController->create($request->file('image'), $this->book->id); $this->book->save(); } }
/** * Update the specified resource in storage. * * @param QuestionRequest $request * @param Question $question * @return \Illuminate\Http\Response */ public function update(Request $request, Question $question, ImageController $imageController) { if (Request::ajax()) { if (null == Request::all()) { return response()->json(['response' => 'error in question update', 404], 404); } else { $question = Question::findOrFail(Request::get('pk')); $question[Request::get('name')] = Request::get('value'); $question->update(); return response()->json(['question' => $question, 200], 200); } } else { $question->fill(Input::all()); $question['question_image'] = $imageController->store(Input::file('question_image'), 'image_question', $question['id'], $question['image_question']); for ($i = 0; $i < 4; $i++) { $image_field = 'answer' . $i . '_image'; $question[$image_field] = $imageController->store(Input::file($image_field), 'answer' . $i . '_image', $question['id'], $question[$image_field]); } $question->update(); flash('Question ' . $question->id . ' has been updated. This is how your question will look like:'); return redirect('questions/' . $question->id); } }
/** * This method save the profile image from facebook * @param $url * @return string */ private function saveImageFromUrl($url) { $name = str_random(10) . '.jpg'; //resize to 200px $image = Image::make(str_replace('normal', 'large', $url))->fit(200); $image->save(public_path($name)); ImageController::save('/profiles/', $name, public_path($name)); unlink(public_path($name)); return $name; }