Пример #1
0
 public function postEditStore($storeId)
 {
     $inputData = Input::all();
     if (empty($inputData['store_image'])) {
         $formData = array('store_name' => $inputData['store_name'], 'store_slug' => $inputData['store_slug']);
         $rules = array('store_name' => 'required|unique:stores,store_name' . ($storeId ? ",{$storeId}" : ''), 'store_slug' => 'required|unique:stores,store_slug' . ($storeId ? ",{$storeId}" : ''));
     } else {
         $formData = array('store_name' => $inputData['store_name'], 'store_image' => $inputData['store_image'], 'store_slug' => $inputData['store_slug']);
         $rules = array('store_name' => 'required|unique:stores,store_name' . ($storeId ? ",{$storeId}" : ''), 'store_image' => 'required|image', 'store_slug' => 'required|unique:stores,store_slug' . ($storeId ? ",{$storeId}" : ''));
     }
     $validator = Validator::make($formData, $rules);
     if ($validator->fails()) {
         $validation = $validator->getMessageBag()->toArray();
         foreach ($validation as $k => $v) {
             $val[$k] = $v;
         }
         return Redirect::to('admin/edit-store/' . $storeId)->with('error', $val);
     } else {
         //hash it now
         if (!empty($formData['store_image'])) {
             $file = $formData['store_image'];
             $destinationPath = public_path() . '/uploads/images/store';
             $filename = $file->getClientOriginalName();
             $extension = $file->getClientOriginalExtension();
             $final_img = $filename;
             $upload_success = $file->move($destinationPath, $final_img);
             $img = Image::make($destinationPath . '/' . $final_img);
             $img->resize(300, 150);
             $img->save($destinationPath . '/' . $final_img);
             $formData['store_image'] = $final_img;
         } else {
             $formData['store_image'] = $inputData['saved_image'];
         }
         if (Stores::whereId($storeId)->update($formData)) {
             return Redirect::to('admin/edit-store/' . $storeId)->with('success', 'Store has been Successfuly updated');
         }
     }
 }