Пример #1
0
 /**
  * Update the specified resource in storage.
  *
  * @param  Request  $request
  * @param  int  $id
  * @return Response
  */
 public function update(Request $request, $id)
 {
     //
     // 先验证
     $this->validate($request, ['title' => 'required', 'content' => 'required']);
     //
     $wdInfo = WdInfo::findOrFail($id);
     $wdInfo->title = Input::get('title');
     $wdInfo->content = Input::get('content');
     // 单独处理图片
     $newLogo = ImageUtil::saveImgFromRequest($request, 'logo', 'img/wd/');
     if (!is_null($newLogo)) {
         $wdInfo->logo = $newLogo;
     }
     $newQr = ImageUtil::saveImgFromRequest($request, 'qrImg', 'img/wd/');
     if (!is_null($newQr)) {
         $wdInfo->qr_img = $newQr;
     }
     if ($wdInfo->save()) {
         //            return redirect($request->getPathInfo(). '/edit')->withData([
         //                'wdInfo' => $wdInfo,
         //                'message' => [trans('adminTip.wdInfo.editInfo.success.edit')]
         //            ]);
         return redirect($request->getPathInfo() . '/edit')->withInput()->withOk(trans('adminTip.wdInfo.editInfo.success.edit'));
     } else {
         return Redirect::back()->withInput()->withErrors('error');
     }
 }
Пример #2
0
 /**
  * 修改头像
  *
  * @param Request $request
  * @return string
  */
 public function changeFace(Request $request)
 {
     // 作为FormData上传的数据,用all来接受整个数据然后在通过key获取对应的value
     // 用Input::get(key)的方式是取不到数据的
     $data = Input::all();
     $img = $data['new_face'];
     $imgPath = ImageUtil::saveImg($img, 'img/wd/face/', 80, 80);
     if (!is_null($imgPath)) {
         $user = User::find(Auth::user()->id);
         $user->headImg = $imgPath;
         if ($user->save()) {
             return response()->json(['success' => true, 'facePath' => 'img/wd/face/' . $imgPath]);
         } else {
             return response()->json(['success' => false, 'msgTag' => 'faceSaveFailed']);
         }
     } else {
         return response()->json(['success' => false, 'msgTag' => 'uploadFailed']);
     }
 }
 /**
  * Update the specified resource in storage.
  *
  * @param  Request  $request
  * @param  int  $id
  * @return Response
  */
 public function update(Request $request, $id)
 {
     // 先验证
     $this->validate($request, ['name' => 'required', 'purchasePrice' => 'required', 'price' => 'required', 'wholesalePrice' => 'required', 'description' => 'required']);
     //
     $product = Product::findOrFail($id);
     $product->name = Input::get('name');
     $product->subtitle = Input::get('subtitle');
     $product->category_id = Input::get('category');
     $product->domestic_price = Input::get('purchasePrice');
     $product->retail_price = Input::get('price');
     $product->wholesale_price = Input::get('wholesalePrice');
     $product->count = Input::get('count');
     $product->description = Input::get('description');
     // 单独处理图片
     $newImg = ImageUtil::saveImgFromRequest($request, 'productImg', 'img/wd/product/' . Input::get('category'));
     if (!is_null($newImg)) {
         $product->thumbnail = $newImg;
     }
     if ($product->save()) {
         //            return redirect($request->getPathInfo() . $id . '/edit' )->withMessage([
         //                'ok' => 'new info saved!'
         //            ]);
         return redirect($request->getPathInfo() . '/edit')->withInput()->withOk(trans('adminTip.products.editProduct.ok'));
     } else {
         return Redirect::back()->withInput()->withErrors('error');
     }
 }