public function store() { if (Sentry::check()) { $ued = Sentry::getUser()->id; } $city = Sentry::getuser()->city; $product = new Product(); $product->user_id = $ued; $product->metal = Input::get('metal'); $product->supplier = Input::get('supplier'); $product->grade_a = Input::get('grade_a'); $product->grade_b = Input::get('grade_b'); $product->shape = Input::get('shape'); $product->size_a = Input::get('size_a'); $product->size_b = Input::get('size_b'); $product->size_c = Input::get('size_c'); $product->thickness = Input::get('thickness'); $product->volume = Input::get('volume'); $product->bynumber = Input::get('bynumber'); $product->perday = Input::get('perday'); $product->city = $city; if ($image = Input::file('images')) { $filename = date('Y-m-d-H:i:s') . "-" . rand(1, 100); Image::make($image->getRealPath())->resize(488, 370)->save('public/images/' . $filename); $product->images = 'images/' . $filename; } else { $product->images = 'images/default.jpg'; } $cadfilename = date('Y-m-d-H:i:s') . "-" . rand(1, 100); if (Input::hasfile('files')) { Input::file('files')->move('public/img/', $cadfilename); $product->files = 'img/' . $cadfilename; } else { $product->files = '0'; } $product->save(); return Redirect::to('/list')->with('flash_notice', 'Product added successfully'); }
/** * Update the specified resource in storage. * * @param int $id * @return Response */ public function update() { // Fetch all request data. $data = Input::only('timezone', 'games'); // Build the validation constraint set. $rules = array('timezone' => array('regex:([0-9a-zA-Z /+-]+)')); // Create a new validator instance. $validator = Validator::make($data, $rules); if ($validator->passes()) { try { // Find the user using the user id $user = User::find(Sentry::getuser()->id); // Update the user details $user->timezone = Input::get('timezone'); $user_games = $user->userGame()->get(); $games = Input::get('games'); foreach ($user_games as $user_game) { if ($games && !in_array($user_game->id, $games)) { $user->userGame($user_game)->detach(); } elseif ($games == false) { $user->userGame($user_game)->detach(); } } if ($games) { foreach ($games as $game) { $game_attach = Game::find($game); if (!$user->userGame()->where('game_id', '=', $game_attach->id)->first()) { $user->userGame()->attach($game_attach); } } } // Update the user if ($user->save()) { return Redirect::to('/user/edit')->with('global_success', 'Profile has been updated.'); } else { return Redirect::to('/user/edit')->with('global_error', 'We couldn\'t update your profile, pelase try again or contactu us if situation repeats.'); } } catch (Cartalyst\Sentry\Users\UserExistsException $e) { echo 'User with this login already exists.'; } catch (Cartalyst\Sentry\Users\UserNotFoundException $e) { echo 'User was not found.'; } } return Redirect::to('/user/edit')->withInput()->withErrors($validator)->with('message', 'Validation Errors!'); }