Ejemplo n.º 1
0
 /**
  * Update the specified resource in storage.
  *
  * @param  int  $id
  * @return Response
  */
 public function update($id, CreatePlayerRequest $request, Player $player)
 {
     $player_to_update = $player->find($id);
     $uploaded_image = $request->file('image_upload');
     $parameter = $request->all();
     if (isset($uploaded_image)) {
         $ext = $uploaded_image->getClientOriginalExtension();
         $newImageName = $player_to_update->id . "." . $ext;
         $uploaded_image->move(base_path() . '/public/img/uploads/player/', $newImageName);
         Image::make(base_path() . '/public/img/uploads/player/' . $newImageName, array('width' => 160, 'height' => 200))->save(base_path() . '/public/img/uploads/thumbnails/player/' . $newImageName);
         $parameter = $request->all();
         $parameter['image'] = $newImageName;
         /* remove this field from the parameters list */
         unset($parameter['image_upload']);
         $player_to_update->update($parameter);
     } else {
         $player_to_update->update($parameter);
     }
     Session::flash('message', 'The player was successfully updated!.');
     Session::flash('flash_type', 'alert-success');
     return redirect('players');
 }