public function postPartial(Request $request) { $position = Input::get('position'); $has_next = Input::get('has_next'); $img_id = Input::get('img_id'); $img_partial = null; if ($position === 'top') { $img_partial = $has_next === 'true' ? Hair::find((int) $img_id + 1) : Hair::find((int) $img_id - 1); } else { if ($position === 'middle') { $img_partial = $has_next === 'true' ? Mustache::find((int) $img_id + 1) : Mustache::find((int) $img_id - 1); } else { if ($position === 'bottom') { $img_partial = $has_next === 'true' ? Amulet::find((int) $img_id + 1) : Amulet::find((int) $img_id - 1); } else { if ($position === 'flag') { $img_partial = $has_next === 'true' ? Flag::find((int) $img_id + 1) : Flag::find((int) $img_id - 1); } } } } return response()->json(['url' => $img_partial->image_url, 'id' => $img_partial->id]); }
public function postUpdate() { $data = Request::all(); $user = Auth::user(); $avatar = Avatar::find($user->avatar_id); $validator = $this->validator($data); if ($validator->passes()) { $avatar->update(['mustache_id' => $data['mustache_id'], 'amulet_id' => $data['amulet_id'], 'hair_id' => $data['hair_id'], 'flag_id' => $data['flag_id']]); $page = Input::get('page'); $page = isset($page) ? Input::get('page') : 1; $comment_block_id = $user->comment_block_id; $block = CommentBlock::find($comment_block_id); $comments = $block->getPage($page); $page_count = $block->getPageCount(); $message = 'Не удалось обновить профиль'; $is_error = true; if ($user->update(['name' => $data['name'], 'castle_name' => $data['castle_name']])) { $is_error = false; $message = 'Профиль успешно обновлен'; } return view('user/profile', ['user' => $user, 'block' => $block, 'comments' => $comments, 'page_count' => $page_count, 'page' => $page, 'avatar' => $avatar, 'hair_url' => Hair::find($avatar->hair_id)->image_url, 'mustache_url' => Mustache::find($avatar->mustache_id)->image_url, 'amulet_url' => Amulet::find($avatar->amulet_id)->image_url, 'flag_url' => Flag::find($avatar->flag_id)->image_url, 'is_error' => $is_error, 'message' => $message]); } return view('user/profile', ['user' => $user, 'block' => $block, 'comments' => $comments, 'page_count' => $page_count, 'page' => $page, 'avatar' => $avatar, 'hair_url' => Hair::find($avatar->hair_id)->image_url, 'mustache_url' => Mustache::find($avatar->mustache_id)->image_url, 'amulet_url' => Amulet::find($avatar->amulet_id)->image_url, 'flag_url' => Flag::find($avatar->flag_id)->image_url, 'is_error' => true, 'message' => $validator->messages()->first()]); }