Пример #1
2
 /**
  * Store a newly created resource in storage.
  *
  * @param  Request  $request
  * @return Response
  */
 public function store(ProductRequest $request)
 {
     //
     $data = $request->all();
     if (isset($data['image'])) {
         $thumb = $data['image'];
         $new = 'pro' . uniqid() . '.' . $thumb->getClientOriginalExtension();
         $thumb->move('upload/product', $new);
     }
     $data['image'] = $new;
     $productId = Product::addProduct($data);
     $multi_image = Input::file('multi-images');
     foreach ($multi_image as $multi) {
         # code...
         $thumbnail = 'multi' . uniqid() . '.' . $multi->getClientOriginalExtension();
         $multi->move('upload/multi-image', $thumbnail);
         Image::addImage($productId, $thumbnail);
     }
     if (Input::get('color') != "") {
         $color = Input::get('color');
         foreach ($color as $colorId) {
             # code...
             MapColor::mapColor($colorId, $productId);
         }
     }
     if ($data['other_color'] != "") {
         $other = $data['other_color'];
         $colorId = Color::addColor($other);
         MapColor::mapColor($colorId, $productId);
     }
     if (Input::get('size') != "") {
         $size = Input::get('size');
         foreach ($size as $sizeId) {
             # code...
             MapSize::mapSize($sizeId, $productId);
         }
     }
     if ($data['other_size'] != "") {
         $other = $data['other_size'];
         $sizeId = Size::addSize($other);
         MapSize::mapsize($sizeId, $productId);
     }
     return redirect('admin/product');
     //return "ok";
 }
 public function addProduct()
 {
     $data = ['name' => Request::input('name'), 'description' => Request::input('description'), 'price' => Request::input('price'), 'quantity' => Request::input('quantity'), 'category' => Request::input('add_category'), 'image' => Request::file('cover_image')];
     $productId = Product::addProduct($data);
     return Redirect::to('/admin/produkt/' . $productId)->with('message', 'Produkt został dodany.');
 }