/**
  * Update the specified resource in storage.
  *
  * @param  int $id
  * @return Response
  */
 public function update($id, Request $request)
 {
     // getting all of the post data
     $file = array('image' => Input::file('image'), 'name' => Input::get('name'), 'max_cashback' => Input::get('max_cashback'), "link" => Input::get('link'), 'description' => Input::get('description'), 'featured' => Input::get('featured'));
     $name = Input::get('name');
     $file['slug'] = str_replace(' ', '-', strtolower($name));
     $store = new Store($file);
     $old = Store::findOrFail($id);
     // setting up rules
     $rules = ["name" => "required", 'description' => 'required', 'max_cashback' => 'required', 'slug' => 'required', "link" => "required"];
     //mimes:jpeg,bmp,png and for max size max:10000
     // doing the validation, passing post data, rules and the messages
     $validator = Validator::make($file, $rules);
     if ($validator->fails()) {
         // send back to the page with the input data and errors
         return Redirect::back()->with('store', $store)->withErrors($validator);
     } else {
         if (Input::file('image')) {
             // checking file is valid.
             if (Input::file('image')->isValid()) {
                 $destinationPath = 'stores';
                 // upload path
                 $extension = Input::file('image')->getClientOriginalExtension();
                 // getting image extension
                 $fileName = str_replace(' ', '_', $file['name']) . '_' . rand(111111, 999999) . '.' . $extension;
                 // renameing image
                 Input::file('image')->move($destinationPath, $fileName);
                 // uploading file to given path
                 $file['image'] = $destinationPath . '/' . $fileName;
             } else {
                 // sending back with error message.
                 //                Session::flash('error', 'uploaded file is not valid');
                 return Redirect::back()->withErrors('error', 'uploaded file is not valid');
             }
         } else {
             $file = array_diff($file, array("image" => ""));
         }
         if (!isset($file['featured'])) {
             $file['featured'] = 0;
         }
         $old->update($file);
         Session::flash('status', 'Store updated successfully');
         return Redirect::to('admin/stores');
     }
 }