Exemplo n.º 1
0
 public function store(Request $request)
 {
     $input = $request->all();
     $product = new Product();
     $product->name = $input['name'];
     $product->description = $input['description'];
     $product->sku = $input['sku'];
     $product->price = $input['price'];
     $product->special_price = $input['special_price'];
     if ($input['category'] != null) {
         $product->category = $input['category'];
     }
     $product->is_active = $input['is_active'];
     $product->quanlity = $input['quanlity'];
     $product->save();
     if (!is_null($input['images'])) {
         $path = "/catalog/img/product/" . $product->id . "/";
         foreach ($request->images as $img) {
             $img_product = new ProductImage();
             $img_product->pro_id = $product->id;
             $imgName = $img->getClientOriginalName();
             $img_product->pro_id = $product->id;
             $img_product->path = $path . $imgName;
             $img->move(public_path($path), $imgName);
             $img_product->save();
         }
     }
     return redirect('admin/product');
 }
 public function add(Request $request)
 {
     $category = Category::all();
     if ($request->isMethod('post')) {
         $input = $request->all();
         $fileName = null;
         if (!empty($input['image_url'])) {
             $file = $input['image_url'];
             $extension = $file->getClientOriginalExtension();
             $fileName = rand(11111, 99999) . '.' . $extension;
             $file->move("admin/product", $fileName);
             $destinationPath = "admin/product";
             $fileThumb = "400x300_" . $fileName;
             $fileThumbBig = "600x500_" . $fileName;
             $img = Image::make("{$destinationPath}/{$fileName}")->resize(400, 300);
             $img->save("{$destinationPath}/{$fileThumb}");
             $imgBig = Image::make("{$destinationPath}/{$fileName}")->resize(600, 500);
             $imgBig->save("{$destinationPath}/{$fileThumbBig}");
         }
         $product = new Product();
         $product->price = $input['price'];
         $product->code = $input['code'];
         $product->categories_id = $input['category'];
         $product->image_url = $fileName;
         $product->slug = $this->slugify($input['title']);
         $product->translateOrNew(LaravelLocalization::setLocale())->title = $input['title'];
         $product->translateOrNew(LaravelLocalization::setLocale())->summary = $input['summary'];
         $product->translateOrNew(LaravelLocalization::setLocale())->description = $input['description'];
         $product->save();
         return redirect(LaravelLocalization::setLocale() . DIRECTORY_SEPARATOR . 'admin-product');
     }
     return view('admin.products.add', compact('category'));
 }
 /**
  * Store a newly created resource in storage.
  *
  * @return Response
  */
 public function store(Request $request)
 {
     // Validation //
     $validation = Validator::make($request->all(), ['caption' => 'required|regex:/^[A-Za-z ]+$/', 'description' => 'required', 'userfile' => 'required|image|mimes:jpeg,png|min:1|max:1000']);
     // Check if it fails //
     if ($validation->fails()) {
         return redirect()->back()->withInput()->with('errors', $validation->errors());
     }
     // Process valid data & go to success page //
     $product = new Product();
     $category_id = DB::table('categories')->where('name', $request->input('category'))->value('id');
     $file = $request->file('userfile');
     $destination_path = 'uploads/';
     $filename = date('s-i-H-d-m-y') . '.' . $file->getClientOriginalExtension();
     $file->move($destination_path, $filename);
     $file_path = $destination_path . $filename;
     $imagine = new Imagine();
     $mode = ImageInterface::THUMBNAIL_INSET;
     $imagine->open($file_path)->thumbnail(new Box(250, 250), $mode)->save($file_path);
     $product->file = $file_path;
     $product->category_id = $category_id;
     $product->caption = $request->input('caption');
     $product->description = $request->input('description');
     $product->price = $request->input('price');
     //$product->available = $request->input('available');
     $product->save();
     return redirect('admin/products')->with('message', 'You just uploaded a product!');
 }
Exemplo n.º 4
0
 public function store()
 {
     $data = Input::all();
     try {
         $p = new Product();
         $p->name = Input::get('name');
         $p->description = Input::get('description');
         $p->price = Input::get('price');
         $p->active = 1;
         $p->manufacturer_id = Input::get('manufacturer');
         $p->rating = Input::get('rating');
         $p->stock = Input::get('stock');
         $p->created_at = time();
         $p->updated_at = time();
         $p->slug = Str::slug($p->name);
         $p->save();
         $images = array_filter(explode('###', Input::get('images')));
         foreach ($images as $image) {
             $img = new ProductImgs();
             $img->product_id = $p->id;
             $img->url = $image;
             $img->created_at = time();
             $img->updated_at = time();
             $img->save();
         }
     } catch (Exception $e) {
         print_r($e->getMessage());
         $this->code = 400;
     }
     Response::json([], $this->code);
 }
Exemplo n.º 5
0
 /**
  * Store a newly created resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @return \Illuminate\Http\Response
  */
 public function store(Request $request)
 {
     // Validation //
     $validation = Validator::make($request->all(), ['name' => 'required|unique:category_subs|max:255', 'categories' => 'required', 'sub_categories' => 'required', 'description' => 'required', 'price' => 'required', 'weight' => 'required', 'keyword' => 'required']);
     $cur_clean = preg_replace('/\\./', '', $request->input('price'));
     $kg = preg_replace('/\\,/', '.', $request->input('weight'));
     $gram = $kg * 1000;
     // Check if it fails //
     if ($validation->fails()) {
         return redirect()->back()->withInput()->with('errors', $validation->errors());
     }
     if ($request->input('publish') == "") {
         $publish = 0;
     } else {
         $publish = 1;
     }
     $author = Auth::user()->id;
     $product = new Product();
     $seo = $request->input('name');
     $seotitle = SeoHelper::seotitle($seo);
     // save product data into database //
     $product->name = $request->input('name');
     $product->name_seo = $seotitle;
     $product->id_categories = $request->input('categories');
     $product->id_category_subs = $request->input('sub_categories');
     $product->id_user = $author;
     $product->base_price = $cur_clean;
     $product->base_weight = $gram;
     $product->keyword = $request->input('keyword');
     $product->description = $request->input('description');
     $product->publish = $publish;
     $product->save();
     Alert::success('Success Create ' . $request->input('name') . ' !')->persistent("Close");
     return redirect('dropmin/product/list')->with('message', 'You just create product!');
 }
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     $ratatouille = new App\Product();
     $ratatouille->week_no = date('W');
     $ratatouille->year = date('Y');
     $ratatouille->name = 'Ratatouille';
     $ratatouille->description = 'Ratatouille is een Frans gerecht van gestoofde groenten, dat vooral in de Provence veel wordt bereid.';
     $ratatouille->city_id = 1;
     $ratatouille->save();
     $spaghetti = new App\Product();
     $spaghetti->week_no = date('W');
     $spaghetti->year = date('Y');
     $spaghetti->name = 'Spaghetti';
     $spaghetti->description = 'Lorem ipsum.';
     $spaghetti->city_id = 1;
     $spaghetti->save();
     $visgerecht = new App\Product();
     $visgerecht->week_no = date('W');
     $visgerecht->year = date('Y');
     $visgerecht->name = 'Visgerecht';
     $visgerecht->description = 'Lorem ipsum.';
     $visgerecht->city_id = 2;
     $visgerecht->save();
     $testgerecht = new App\Product();
     $testgerecht->week_no = date('W');
     $testgerecht->year = date('Y');
     $testgerecht->name = 'Test gerecht';
     $testgerecht->description = 'Lorem ipsum.';
     $testgerecht->city_id = 2;
     $testgerecht->save();
 }
Exemplo n.º 7
0
 public function store(Request $request)
 {
     // validate
     // read more on validation at http://laravel.com/docs/validation
     $rules = array('name' => 'required', 'brand' => 'required', 'price' => 'required|numeric');
     $messages = ['required' => 'The :attribute field is required.', 'numeric' => 'The :attribute field must be numeric.'];
     $validator = Validator::make(Input::all(), $rules, $messages);
     if ($validator->fails()) {
         return response()->json(['error' => ['status' => ['code' => 400, 'statusText' => 'Bad Request'], 'errors' => $validator->errors()->all(), 'message' => 'Invalid request body. Ensure all fields are specified and in JSON format.']]);
     } else {
         $product = new Product();
         $product->name = Input::get('name');
         $product->brand = Input::get('brand');
         $product->price = Input::get('price');
         $product->created_at = new DateTime();
         $product->updated_at = new DateTime();
         if (Input::get('description') != null) {
             $product->description = Input::get('description');
         } else {
             $product->description = '<small>No Descriptions</small>';
         }
         if (Input::get('imageUrl') == null) {
             $product->imageUrl = 'https://cdn.filestackcontent.com/CwyooxXdTcWtwufoKgOf';
         } else {
             $product->imageUrl = Input::get('imageUrl');
         }
         if ($product->save()) {
             return response()->json(['success' => true, 'product' => $product]);
         } else {
             return response()->json(['error' => ['status' => ['code' => 500, 'statusText' => 'Internal Server Error'], 'message' => 'Failed to create new product.']]);
         }
     }
 }
 /**
  * Store a newly created resource in storage.
  *
  * @param  Request  $request
  * @return Response
  */
 public function store(Request $request)
 {
     // 验证一下必填项
     $this->validate($request, ['name' => 'required', 'productImg' => 'required', 'purchasePrice' => 'required', 'price' => 'required', 'wholesalePrice' => 'required', 'description' => 'required']);
     $status = ['ok' => false, 'msg' => ''];
     $imgPath = ImageUtil::saveImgFromRequest($request, 'productImg', 'img/wd/product/' . Input::get('category'));
     if (!is_null($imgPath)) {
         $product = new Product(['name' => Input::get('name'), 'subtitle' => Input::get('subtitle'), 'thumbnail' => $imgPath, 'category_id' => Input::get('category'), 'domestic_price' => Input::get('purchasePrice'), 'retail_price' => Input::get('price'), 'wholesale_price' => Input::get('wholesalePrice'), 'count' => Input::get('count'), 'description' => Input::get('description')]);
         if (!$product->save()) {
             $status['msg'] = trans('products.addNewProduct.errors.addError');
         } else {
             $status['ok'] = true;
             // 这里需要记录一下进货记录
             $log = new InventoryLog(['product_id' => $product->id, 'count' => Input::get('count'), 'price' => Input::get("purchasePrice"), 'type' => InventoryConfig::IN]);
             $log->save();
         }
     } else {
         $status['msg'] = trans('products.addNewProduct.errors.imgError');
     }
     if ($status['ok']) {
         //            return Redirect::back()->withMessage(['ok' => trans('products.addNewProduct.success.added')]);
         // 暂时跳转到信息列表页面吧
         //            return redirect($request->getPathInfo());
         //            return redirect($request->getPathInfo() . '/create')->withMessages(
         //                ['ok' => trans('products.addNewProduct.success.added')]
         //            );
         return redirect($request->getPathInfo())->withOk(trans('products.addNewProduct.success.added'));
     } else {
         return Redirect::back()->withInput()->withErrors($status['msg']);
     }
 }
Exemplo n.º 9
0
 /**
  *
  */
 public function loadFeed()
 {
     $xml = $this->reader->load($this->feedUrl);
     $content = $xml->getContent();
     $this->content = $xml->getContent();
     foreach ($content as $product) {
         $item = Product::where('externalUrl', '=', $product->productUrl)->first();
         if (!$item) {
             $item = new Product();
         }
         if (strlen($product->brand) > 1) {
             $brand = Brand::where('name', '=', $product->brand)->first();
             if (!$brand) {
                 $brand = new Brand();
                 $brand->name = $product->brand;
                 $brand->save();
             }
             if ($brand->id) {
                 $item->brand = $brand->id;
             }
         }
         $item->name = $product->name;
         $item->description = $product->description;
         $item->price = $product->price;
         $item->regularPrice = $product->regularPrice;
         $item->shippingPrice = $product->shippingPrice;
         $item->externalUrl = $product->productUrl;
         $item->imageUrl = $product->graphicUrl;
         $item->save();
     }
 }
 public function import(Request $request)
 {
     $file = $request->file('arquivo');
     $extension = $file->getClientOriginalExtension();
     $import = new Import();
     $import->user_id = 1;
     $import->save();
     Storage::disk('local')->put($import->id . '.' . $extension, File::get($file));
     $handle = fopen($file, "r");
     $firstTime = true;
     while (($line = fgetcsv($handle, 1000, "\t")) !== false) {
         if ($firstTime) {
             $firstTime = false;
         } else {
             $produto = new Product();
             $produto->import_id = $import->id;
             $produto->purchaser_name = $line[0];
             $produto->item_description = $line[1];
             $produto->item_price = floatval($line[2]);
             $produto->purchase_count = intval($line[3]);
             $produto->merchant_address = $line[4];
             $produto->merchant_name = $line[5];
             $produto->save();
         }
     }
     return view('index', ['imports' => Import::all()]);
 }
Exemplo n.º 11
0
 /**
  * Store a newly created resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @return \Illuminate\Http\Response
  */
 public function store(Request $request)
 {
     $this->validate($request, ['product_title' => 'required']);
     $product = new Product();
     $product->is_published = $request->get('is_published') == 'on' ? 1 : 0;
     $product->title = $request->get('product_title');
     $product->description = $request->get('product_description');
     $product->min_player = $request->get('product_input-players-min');
     $product->max_player = $request->get('product_input-players-max');
     $product->min_age = $request->get('product_input-age-min');
     $product->cost_price = $request->get('product_costprice');
     $product->sale_price = $request->get('product_saleprice');
     $product->save();
     if ($request->get('product_categories') != null) {
         foreach ($request->get('product_categories') as $category_id) {
             $product->categories()->attach($category_id);
         }
     }
     $files = $request->file('product_images');
     $count = 0;
     foreach ($files as $file) {
         if ($file == null) {
             continue;
         }
         $product->addMedia($file)->usingFileName($product->id . "_" . $count . "." . $file->getClientOriginalExtension())->toCollection('images');
         $count++;
     }
     Session::flash('flash_message', 'Product successfully added!');
     return view('dashboard/create_product')->with('categories', Category::get())->with('product', new Product());
 }
 /**
  * Store a newly created resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @return \Illuminate\Http\Response
  */
 public function store(ProductRequest $product_request)
 {
     $product = new Product();
     $file_name = $product_request->file('illustration')->getClientOriginalName();
     $product->product_name = $product_request->name;
     $product->cate_id = $product_request->cate_id;
     $product->brand_id = $product_request->brand_id;
     $product->qty = $product_request->qty;
     $product->price = $product_request->price;
     $product->discount = $product_request->discount;
     $product->description = $product_request->description;
     $product->show = $product_request->show;
     $product->feature = $product_request->feature;
     $product->image_name = $file_name;
     $product->slug = $product_request->slug;
     $product_request->file('illustration')->move('upload', $file_name);
     $product->save();
     $product->size()->sync($product_request->size);
     $product->color()->sync($product_request->color);
     $product_id = $product->id;
     if (Input::hasFile('images')) {
         foreach (Input::file('images') as $file) {
             $image = new Image();
             if (isset($file)) {
                 $image->image_name = $file->getClientOriginalName();
                 $image->product_id = $product_id;
                 $file->move('upload/images', $file->getClientOriginalName());
                 $image->save();
             }
         }
     }
     return redirect()->route('admin.product.index')->with('alert-success', 'ADD complete');
 }
Exemplo n.º 13
0
 /**
  * Store a newly created resource in storage.
  *
  * @return Response
  */
 public function store(ProductCreateRequest $request)
 {
     $product = new Product(array('name' => $request->get('name'), 'sku' => $request->get('sku'), 'price' => $request->get('price'), 'description' => $request->get('description'), 'is_downloadable' => $request->get('is_downloadable')));
     $product->save();
     // Process the uploaded image
     $imageName = $product->sku . '.' . $request->file('image')->getClientOriginalExtension();
     $request->file('image')->move(base_path() . '/public/imgs/products/', $imageName);
     // Process the electronic download
     if ($request->file('download')) {
         $downloadName = $product->sku . '.' . $request->file('download')->getClientOriginalExtension();
         $request->file('download')->move(storage_path() . '/downloads/', $downloadName);
         $product->download = $downloadName;
         $product->save();
     }
     return \Redirect::route('admin.products.edit', array($product->id))->with('message', 'The product has been added!');
 }
Exemplo n.º 14
0
 /**
  * Store a newly created resource in storage.
  *
  * @param  \Illuminate\Http\Request $request
  * @return \Illuminate\Http\Response
  */
 public function store(Request $request)
 {
     try {
         $user = JWTAuth::parseToken()->authenticate();
         if ($user) {
             $data = ['product_code' => $request->product_code];
             $des = ['name' => $request->name, 'price' => $request->price];
             $productCollection = Product::where($data)->get();
             $product_des = new ProductDescription($des);
             if ($productCollection->isEmpty()) {
                 //if collection not exist mean there is no entry of the productCode before
                 $product = new Product($data);
                 $product->save();
                 $product_des->product()->associate($product);
             } else {
                 //since collection have some data get the product code from before n use it
                 $product = $productCollection[0];
                 //check if user already have the product with this product code
                 $array1 = $user->product_descriptions;
                 $array2 = $product->product_descriptions;
                 if (!$array1->intersect($array2)->isEmpty()) {
                     ///if there is an instance of product description in it return error with msg in json
                     return response()->json(['message' => 'Error Product Existed']);
                 }
                 $product_des->product()->associate($product);
             }
             $user->product_descriptions()->save($product_des);
             $message = ["message" => "Product Submitted"];
             return json_encode($message);
         }
     } catch (JWTException $e) {
     }
     return response("Invalid User", 401);
 }
Exemplo n.º 15
0
 /**
  * Register a product via barcode and uid (user id)
  *
  * @return \Illuminate\Http\JsonResponse
  */
 public function scan()
 {
     header("Access-Control-Allow-Origin: *");
     $response = new YYResponse(FALSE, 'Something went wrong.');
     $validator = Validator::make(Request::all(), ['barcode' => 'required|integer', 'uid' => 'required|integer']);
     if ($validator->fails()) {
         $response->errors = $validator->errors();
         return response()->json($response);
     }
     $product = Product::where(['barcode' => Request::get('barcode')])->get();
     $product = empty($product[0]) ? NULL : $product[0];
     if (empty($product)) {
         $product = new Product();
         $product->barcode = Request::get('barcode');
         $product->uid = Request::get('uid');
         $product->save();
     }
     if (!empty($product)) {
         $response->state = TRUE;
         $response->message = NULL;
         $response->data = $product;
         $response->data->reviews = Product::getReviewsById($product->id);
         $response->data->rating = Product::getRatingById($product->id);
         $response->data->rating->average = $response->data->rating->count > 0 ? $response->data->rating->total / $response->data->rating->count : 0;
         $response->data->review = Product::getReviewsById($product->id, $product->uid);
     }
     return response()->json($response);
 }
 public function guardarDatos($request, $id)
 {
     $rules = ['name' => 'required', 'price' => 'required', 'id_category' => 'required'];
     $this->validate($request, $rules);
     if ($id != null) {
         $producto = Product::findOrFail($id);
     } else {
         $producto = new Product();
     }
     $producto->name = $request->input('name');
     $producto->description = $request->input('description');
     $producto->price = $request->input('price');
     $producto->id_category = $request->input('id_category');
     $producto->save();
     $colors = Color::orderBy('name', 'asc')->get();
     foreach ($colors as $col) {
         $checkColor = $request->input('color' . $col->id);
         if (isset($checkColor)) {
             $products_colors = ProductColor::where('id_color', $col->id)->where('id_product', $producto->id)->first();
             if (!isset($products_colors->id)) {
                 $products_colors = new ProductColor();
             }
             $products_colors->id_color = $col->id;
             $products_colors->id_product = $producto->id;
             $products_colors->save();
         } else {
             $products_colors = ProductColor::where('id_color', $col->id)->where('id_product', $producto->id)->first();
             if (isset($products_colors->id)) {
                 $products_colors->delete();
             }
         }
     }
 }
Exemplo n.º 17
0
 /**
  * Store a newly created resource in storage.
  *
  * @return Response
  */
 public function store()
 {
     //return 'test';
     $rules = array('product_name' => 'required', 'product_price' => 'required');
     //print_r($rules);
     // Create a new validator instance from our validation rules
     $validator = Validator::make(Input::all(), $rules);
     // If validation fails, we'll exit the operation now.
     if ($validator->fails()) {
         // Ooops.. something went wrong
         //  echo "validation issues...";
         return Redirect::back()->withInput()->withErrors($validator);
     }
     //return 'i am here';
     // Input::get('first_name');
     $data = new Product();
     $data->product_name = Input::get('product_name');
     $data->product_code = Input::get('product_code');
     $data->product_price = Input::get('product_price');
     $data->is_active = Input::has('is_active') ? 1 : 0;
     //return $data;exit;
     //$data->image_name = $safeName;
     //  echo '<pre>';
     //  print_r($data);
     //  echo '</pre>';
     // die;
     if ($data->save()) {
         //echo 'i am in save';
         return redirect()->route("products")->with('message', 'Success');
         //return redirect()->action('HomeController@index');
     } else {
         return Redirect::back()->with('error', Lang::get('banners/message.error.create'));
     }
 }
 public function store(Request $request)
 {
     $ingredients = Ingredient::get()->toArray();
     $newProduct = new Product();
     $newProduct->week_no = $request->input('week_no');
     $newProduct->year = $request->input('year');
     $newProduct->name = $request->input('name');
     $newProduct->description = $request->input('description');
     $newProduct->city_id = 1;
     $newProduct->save();
     foreach ($request->input('ingredient-list') as $inputIngredient) {
         $ingredientSearch = array_search($inputIngredient, array_column($ingredients, 'name'));
         if ($ingredientSearch === false) {
             $newIngredient = new Ingredient();
             $newIngredient->name = $inputIngredient;
             $newIngredient->unit = 'stuks';
             $newIngredient->type = 'groente';
             $newIngredient->min_amount = 1;
             if (!$newIngredient->save()) {
                 abort(500);
             }
             $attachIngredientToProduct = new IngredientsInProduct();
             $attachIngredientToProduct->product_id = $newProduct->id;
             $attachIngredientToProduct->ingredient_id = $newIngredient->id;
             $attachIngredientToProduct->save();
         } else {
             $attachIngredientToProduct = new IngredientsInProduct();
             $attachIngredientToProduct->product_id = $newProduct->id;
             $attachIngredientToProduct->ingredient_id = $ingredients[$ingredientSearch]['id'];
             $attachIngredientToProduct->save();
         }
     }
     return redirect('manager/products');
 }
Exemplo n.º 19
0
 /**
  * Store a newly created resource in storage.
  *
  * @param  Request  $request
  * @return Response
  */
 public function store(Request $request)
 {
     $validator = Validator::make($request->all(), ['image' => 'mimes:jpeg,png,jpg', 'brand_id' => 'required', 'name' => 'required', 'category_id' => 'required', 'quantity' => 'required']);
     if ($validator->fails()) {
         return redirect('products/create')->withErrors($validator)->withInput();
     }
     $image = Input::file('image');
     $filename = date('YmdHis') . "-" . $image->getClientOriginalName();
     if ($request->has('popular')) {
         $popular = "Yes";
     } else {
         $popular = "No";
     }
     if ($request->has('active')) {
         $brand = new Product(array('name' => $request->get('name'), 'image' => $filename, 'brand_id' => $request->get('brand_id'), 'category_id' => $request->get('category_id'), 'quantity' => $request->get('quantity'), 'rent_one_week' => $request->get('rent_one_week'), 'rent_one_month' => $request->get('rent_one_month'), 'rent_three_month' => $request->get('rent_three_month'), 'rent_six_month' => $request->get('rent_six_month'), 'rent_nine_month' => $request->get('rent_nine_month'), 'rent_twelve_month' => $request->get('rent_twelve_month'), 'description' => $request->get('description'), 'model' => $request->get('model'), 'active' => "Enable", 'popular' => $popular));
         $brand->save();
         $request->file('image')->move(base_path() . '/public/admin/productimage/', $filename);
         return redirect('products');
     } else {
         $brand = new Product(array('name' => $request->get('name'), 'image' => $filename, 'brand_id' => $request->get('brand_id'), 'category_id' => $request->get('category_id'), 'quantity' => $request->get('quantity'), 'rent_one_week' => $request->get('rent_one_week'), 'rent_one_month' => $request->get('rent_one_month'), 'rent_three_month' => $request->get('rent_three_month'), 'rent_six_month' => $request->get('rent_six_month'), 'rent_nine_month' => $request->get('rent_nine_month'), 'rent_twelve_month' => $request->get('rent_twelve_month'), 'description' => $request->get('description'), 'model' => $request->get('model'), 'popular' => $popular));
         $brand->save();
         $request->file('image')->move(base_path() . '/public/admin/productimage/', $filename);
         return redirect('products');
     }
 }
Exemplo n.º 20
0
 /**
  * Store a newly created resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @return \Illuminate\Http\Response
  */
 public function store(Request $request)
 {
     // Validation //
     $validation = Validator::make($request->all(), ['caption' => 'required|regex:/^[A-Za-z ]+$/', 'description' => 'required', 'userfile' => 'required|image|mimes:jpeg,png|min:1|max:5250']);
     // Check if it fails //
     if ($validation->fails()) {
         return redirect()->back()->withInput()->with('errors', $validation->errors());
     }
     $product = new Product();
     // upload the product //
     $image = $request->file('userfile');
     $filename = time() . '.' . $image->getClientOriginalExtension();
     $path = public_path('assets/products/' . $filename);
     $img = Image::make($image->getRealPath());
     // resize the image to a width of 300 and constrain aspect ratio (auto height)
     $img->resize(300, null, function ($constraint) {
         $constraint->aspectRatio();
     });
     $img->save($path);
     $seo = $request->input('caption');
     $seotitle = SeoHelper::seotitle($seo);
     // save product data into database //
     $product->file = $filename;
     $product->caption = $request->input('caption');
     $product->description = $seotitle;
     $product->save();
     Alert::success('Success Create!')->persistent("Close");
     return redirect('dropmin/product/list')->with('message', 'You just uploaded an image!');
 }
Exemplo n.º 21
0
 public function postAdd(ProductRequest $request_product)
 {
     $product = new Product();
     $file_name = $request_product->file('fileimages')->getClientOriginalName();
     $product->name = $request_product->txtten;
     $product->alias = str_slug($request_product->txtten);
     $product->price = $request_product->txtgia;
     $product->pricesale = $request_product->txtgiasale;
     $product->intro = $request_product->txtndhienthi;
     $product->content = $request_product->txtndchitiet;
     $product->image = $file_name;
     $product->keywork = $request_product->txtkeyword;
     $product->discription = $request_product->txtmota;
     $product->user_id = Auth::user()->id;
     $product->cate_id = $request_product->parentid;
     $request_product->file('fileimages')->move('public/upload/', $file_name);
     $product->save();
     $product_id = $product->id;
     if (Input::hasFile('fileimageschitiet')) {
         foreach (Input::file('fileimageschitiet') as $file) {
             $product_img = new ProductImage();
             if (isset($file)) {
                 $product_img->image = $file->getClientOriginalName();
                 $product_img->product_id = $product_id;
                 $file->move('public/upload/images_detail/', $file->getClientOriginalName());
                 $product_img->save();
             }
         }
     }
     return redirect()->route('admin.product.getList')->with(['flash_level' => 'success', 'flash_message' => 'Thêm sản phẩm thành công']);
 }
Exemplo n.º 22
0
 public function create()
 {
     $data = ['name' => Input::get('name'), 'title' => Input::get('title'), 'description' => Input::get('description'), 'category_id' => Input::get('category_id'), 'price' => Input::get('price'), 'VAT' => Input::get('VAT'), 'size' => Input::get('size'), 'color' => Input::get('color'), 'material' => Input::get('material'), 'details' => Input::get('details'), 'weight' => Input::get('weight'), 'stock' => Input::get('stock')];
     if (isset($data) && is_array($data)) {
         $product = new Product();
         if ($product->validate($data)) {
             $product->name = $data['name'];
             $product->title = $data['title'];
             $product->description = $data['description'];
             $product->category_id = $data['category_id'];
             $product->price = $data['price'];
             $product->VAT = $data['VAT'];
             $product->size = $data['size'];
             $product->color = $data['color'];
             $product->material = $data['material'];
             $product->details = $data['details'];
             $product->weight = $data['weight'];
             $product->stock = $data['stock'];
             if (Input::file('image')->isValid()) {
                 $fileName = rand(11111, 99999) . '.' . Input::file('image')->getClientOriginalExtension();
                 Input::file('image')->move('images/products/' . $product->id . '/', $fileName);
                 $product->image = $product->id . '/' . $fileName;
             } else {
                 return Redirect::route('products')->with(['msg' => 'Failed to create!']);
             }
             $create = $product->save();
             if (!$create) {
                 return Redirect::route('products')->with(['msg' => 'Failed to create!']);
             }
             return Redirect::route('products')->with(['msg' => 'Successfully created!']);
         }
         return Redirect::route('products')->with(['msg' => 'Failed to create!']);
     }
     return Redirect::route('products')->with(['msg' => 'Failed to create!']);
 }
Exemplo n.º 23
0
 public function saveProduct(Request $request)
 {
     $result = array('success' => 0);
     $image = $request->session()->get('image');
     if (!empty($image)) {
         $a = explode('-', basename($image));
         $id = array_shift($a);
         if (intval($id) > 0) {
             $prods_dir = 'uploads/product';
             $image_noid = implode('-', $a);
             $prod = new Product();
             $prod->image = $image_noid;
             $prod->left = floatval($request->input('left'));
             $prod->top = floatval($request->input('top'));
             $prod->width = floatval($request->input('width'));
             if ($prod->save()) {
                 if (rename($image, $prods_dir . '/' . $prod->id . '-' . $image_noid) && rename(dirname($image) . '/thumbs/' . basename($image), $prods_dir . '/thumbs/' . $prod->id . '-' . $image_noid)) {
                     $request->session()->forget('image');
                     $result['success'] = 1;
                 }
             }
         }
     }
     return response()->json($result);
 }
 /**
  * Store a newly created resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @return \Illuminate\Http\Response
  */
 public function store(Request $request)
 {
     $product = new Product();
     $product->tax_group_id = 1;
     // @todo: koppeling maken met i18n tabel via de Translatable Package.
     // $product->$request->input('product.name');
     $product->save();
 }
Exemplo n.º 25
0
 protected function transfer(\App\Product $product)
 {
     $pData = unserialize($product->data);
     $pData->setCategory(5);
     $product->data = serialize($pData);
     $product->cat_id = 5;
     $product->save();
 }
Exemplo n.º 26
0
 /**
  * Create a new product.
  *
  * @param  Request  $request
  * @return Response
  */
 public function store(Request $request)
 {
     $this->validate($request, ['name' => 'required|max:255']);
     $product = new Product();
     $product->name = $request->name;
     $product->save();
     return redirect('/products');
 }
Exemplo n.º 27
0
 /**
  * Store a newly created resource in storage.
  *
  * @param  \Illuminate\Http\Request $request
  * @return \Illuminate\Http\Response
  */
 public function store(ProductRequest $request)
 {
     $product = new Product();
     $product->fill($request->all());
     $product->section = str_replace('products.', '', $request->section);
     $product->save();
     return redirect(route($request->section))->with('message', 'Producto creado corectamente');
 }
Exemplo n.º 28
0
 /**
  * Store a newly created resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @return \Illuminate\Http\Response
  */
 public function store(Request $request)
 {
     $product = new Product();
     $product->name = Input::get('name');
     $product->description = Input::get('description');
     $product->save();
     return view('products.index', ['products' => Product::all()]);
 }
Exemplo n.º 29
0
 /**
  * Update the specified resource in storage.
  *
  * @param  Request  $request
  * @param  int  $id
  * @return Response
  */
 public function update(Request $request, Product $product)
 {
     $product->fill($request->all());
     $product->slug = str_slug($request->get('name'));
     $product->visible = $request->has('visible') ? 1 : 0;
     $updated = $product->save();
     $message = $updated ? 'Producto actualizado correctamente!' : 'El producto NO pudo actualizarse!';
     return redirect()->route('admin.product.index')->with('message', $message);
 }
Exemplo n.º 30
0
 /**
  * Store a newly created resource in storage.
  *
  * @return Response
  */
 public function store()
 {
     $product = new Product();
     $product->name = Input::get('name');
     $product->email = Input::get('email');
     $product->subject = Input::get('subject');
     $product->message = Input::get('message');
     $product->save();
 }