当前位置: 首页>>代码示例>>PHP>>正文


PHP Product::create方法代码示例

本文整理汇总了PHP中app\Product::create方法的典型用法代码示例。如果您正苦于以下问题:PHP Product::create方法的具体用法?PHP Product::create怎么用?PHP Product::create使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在app\Product的用法示例。


在下文中一共展示了Product::create方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: store

 /**
  * Store a newly created resource in storage.
  *
  * @param  Request  $request
  * @return Response
  */
 public function store(Request $request)
 {
     $this->validate($request, ['name' => 'required', 'units' => 'required']);
     Product::create($request->all());
     message()->success('Successfully created Product');
     return ['location' => action('ProductsController@index')];
 }
开发者ID:johnleider,项目名称:psj,代码行数:13,代码来源:ProductsController.php

示例2: store

 /**
  * Create a new product.
  *
  * @param  Request  $request
  * @return Response
  */
 public function store(Request $request)
 {
     $this->validate($request, ['name' => 'required|max:255', 'store_id' => 'required', 'location_id' => 'required', 'source_id' => 'required']);
     if (!$request->id) {
         $request->quantity = $request->quantity ? $request->quantity : 1;
         Product::create(['name' => $request->name, 'store_id' => $request->store_id, 'location_id' => $request->location_id, 'source_id' => $request->source_id, 'purchase_price' => $request->purchase_price, 'sale_price' => $request->sale_price, 'shipping_paid' => $request->shipping_paid, 'actual_shipping' => $request->actual_shipping, 'seller_fee' => $request->seller_fee, 'shipping_fee' => $request->shipping_fee, 'product_status' => $request->product_status, 'quantity' => $request->quantity, 'quantity_sold' => $request->quantity_sold, 'improvement_hours' => $request->improvement_hours, 'improvement_dollars' => $request->improvement_dollars]);
     } else {
         $product = Product::find($request->id);
         $product->name = $request->name;
         $product->store_id = $request->store_id;
         $product->location_id = $request->location_id;
         $product->source_id = $request->source_id;
         $product->purchase_price = $request->purchase_price;
         $product->sale_price = $request->sale_price;
         $product->shipping_paid = $request->shipping_paid;
         $product->actual_shipping = $request->actual_shipping;
         $product->seller_fee = $request->seller_fee;
         $product->shipping_fee = $request->shipping_fee;
         $product->product_status = $request->product_status;
         $product->quantity = $request->quantity;
         $product->quantity_sold = $request->quantity_sold;
         $product->improvement_hours = $request->improvement_hours;
         $product->improvement_dollars = $request->improvement_dollars;
         $product->save();
     }
     if ($request->submit == 'Save') {
         return redirect('/product');
     } else {
         return redirect('/product/create?source=' . $request->source_id . '&store=' . $request->store_id . '&location_id=' . $request->location_id);
     }
     return redirect('/product');
 }
开发者ID:aducworth,项目名称:inventory,代码行数:38,代码来源:ProductController.php

示例3: run

 public function run()
 {
     foreach (range(1, 12) as $item) {
         $product = ['nombre' => ucfirst($this->faker->words(2, true)), 'precio' => $this->faker->randomFloat(2, 10, 150), 'modelo' => ucfirst($this->faker->word), 'disponible' => 1, 'genero_id' => $this->faker->numberBetween(1, 4), 'tipo_id' => $this->faker->numberBetween(1, 8), 'categoria_id' => $this->faker->numberBetween(1, 7), 'marca_id' => $this->faker->numberBetween(1, 5), 'created_by' => 1];
         Product::create($product);
     }
 }
开发者ID:nbpalomino,项目名称:ProjectMia,代码行数:7,代码来源:ProductTableSeeder.php

示例4: storeNewProduct

 /**
  * @param StoreProductRequest $request
  * @return \Illuminate\Http\JsonResponse
  */
 public function storeNewProduct(StoreProductRequest $request)
 {
     $formData = $request->all();
     $product = Product::create(['product_name' => $formData['product_name'], 'product_price' => $formData['product_price'] * 100, 'long_description' => $formData['long_description'], 'short_description' => $formData['short_description'], 'meta_description' => $formData['meta_description'], 'category_id' => $formData['category_id'], 'is_active' => $formData['is_active']]);
     $this->addToBillys($product);
     return response()->json(['success' => true, 'Message' => 'Your product was created.']);
 }
开发者ID:Reached,项目名称:webshop,代码行数:11,代码来源:ProductsController.php

示例5: store

 /**
  * Store a newly created resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @return \Illuminate\Http\Response
  */
 public function store(Requests\ProductRequest $request)
 {
     # le $this->validate ci-dessous peut-être supprimé par injection de ProductRequest
     //        dd($request->all());
     // Rappel ci-dessous cette méthode redirige vers le formulaire + rajoute les errors etc...
     //        $this->validate($request, [
     //            'name'          => 'required|string|max:255',
     //            'slug'          => 'string',
     //            'category_id'   => 'integer',
     //            'price'         => 'required|numeric',
     //            'quantity'      => 'integer',
     //            'status'        => 'in:opened,closed',
     //            'published_at'  => 'required|date_format:Y-m-j',
     //            'thumbnail'     => 'image|max:3000', // en byte (octet) donc 3Mo
     //        ]);
     $tags = $request->input('tags');
     $product = Product::create($request->all());
     if (!empty($tags)) {
         $product->tags()->attach($tags);
     }
     # phpini limite le nombre d'octets pour une image téléchargée
     if (!is_null($request->file('thumbnail'))) {
         $im = $request->file('thumbnail');
         // extension de l'image
         $ext = $im->getClientOriginalExtension();
         $uri = str_random(12) . '.' . $ext;
         //            dd($im->move(env('UPLOAD_PATH', './uploads'), $uri));
         $im->move(env('UPLOAD_PATH', './uploads'), $uri);
         // Exception renvoyée par le framework si problem
         # Bien veiller aux fillables de Picture pour que ça marche ci-dessous
         # et !! si on a deja 'move' notre image, getSize ne marche plus, il faut getClientSize
         Picture::create(['uri' => $uri, 'size' => $im->getClientSize(), 'type' => $ext, 'product_id' => $product->id]);
     }
     return back()->with(['alert' => 'done', 'message' => 'produit créé']);
 }
开发者ID:bocanico,项目名称:ProjetStarWars,代码行数:41,代码来源:ProductController.php

示例6: store

 /**
  * Store a newly created resource in storage.
  *
  * @param  Request  $request
  * @return Response
  */
 public function store(SaveProductRequest $request)
 {
     $data = ['name' => $request->get('name'), 'slug' => str_slug($request->get('name')), 'description' => $request->get('description'), 'extract' => $request->get('extract'), 'price' => $request->get('price'), 'image' => $request->get('image'), 'visible' => $request->has('visible') ? 1 : 0, 'category_id' => $request->get('category_id')];
     $product = Product::create($data);
     $message = $product ? 'Producto agregado correctamente!' : 'El producto NO pudo agregarse!';
     return redirect()->route('admin.product.index')->with('message', $message);
 }
开发者ID:primitivorm,项目名称:tienda,代码行数:13,代码来源:ProductController.php

示例7: store

 /**
  * Store a newly created resource in storage.
  *
  * @param StoreProductRequest|\Illuminate\Http\Request $request
  * @return \Illuminate\Http\Response
  */
 public function store(StoreProductRequest $request)
 {
     $input = $request->input();
     $input = $this->setImage($request->file('image'), $input);
     Product::create($input);
     return redirect()->action('ProductController@create');
 }
开发者ID:foadk,项目名称:online-store,代码行数:13,代码来源:ProductController.php

示例8: run

 public function run()
 {
     $faker = Faker::create();
     #Plans store
     for ($i = 0; $i < 3; $i++) {
         $price = $faker->numberBetween(1, 99);
         $stock = $faker->numberBetween(20, 50);
         $id = Product::create(['type' => 'store', 'name' => $faker->unique()->catchPhrase, 'description' => $faker->text(500), 'price' => $price, 'stock' => $stock, 'low_stock' => $faker->randomElement([5, 10, 15])]);
         if ($faker->numberBetween(0, 1)) {
             $percentage = $faker->randomElement([10, 15, 25, 35, 50]);
             ProductOffer::create(['product_id' => $id->id, 'day_start' => $faker->dateTime(), 'day_end' => $faker->dateTimeBetween('now', '+1 years'), 'percentage' => $percentage, 'price' => $percentage * $price / 100, 'quantity' => round($stock / 2)]);
         }
     }
     #modules
     for ($i = 0; $i < 15; $i++) {
         $price = $faker->numberBetween(1, 99);
         $stock = $faker->numberBetween(20, 50);
         $id = Product::create(['type' => 'module', 'name' => $faker->unique()->catchPhrase, 'description' => $faker->text(500), 'price' => $price, 'stock' => $stock, 'low_stock' => $faker->randomElement([5, 10, 15])]);
         if ($faker->numberBetween(0, 1)) {
             $percentage = $faker->randomElement([10, 15, 25, 35, 50]);
             ProductOffer::create(['product_id' => $id->id, 'day_start' => $faker->dateTime(), 'day_end' => $faker->dateTimeBetween('now', '+1 years'), 'percentage' => $percentage, 'price' => $percentage * $price / 100, 'quantity' => round($stock / 2)]);
         }
     }
     #development
     for ($i = 0; $i < 5; $i++) {
         $price = $faker->numberBetween(1, 99);
         $stock = $faker->numberBetween(20, 50);
         $id = Product::create(['type' => 'development', 'name' => $faker->unique()->catchPhrase, 'description' => $faker->text(500), 'price' => $price, 'stock' => $stock, 'low_stock' => $faker->randomElement([5, 10, 15])]);
         if ($faker->numberBetween(0, 1)) {
             $percentage = $faker->randomElement([10, 15, 25, 35, 50]);
             ProductOffer::create(['product_id' => $id->id, 'day_start' => $faker->dateTime(), 'day_end' => $faker->dateTimeBetween('now', '+1 years'), 'percentage' => $percentage, 'price' => $percentage * $price / 100, 'quantity' => round($stock / 2)]);
         }
     }
 }
开发者ID:ant-vel,项目名称:Web,代码行数:34,代码来源:ProductsTableSeeder.php

示例9: run

 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     $faker = Faker\Factory::create();
     for ($i = 0; $i < 10; ++$i) {
         Product::create(['name' => $faker->name, 'category_id' => $faker->numberBetween($min = 1, $max = 10), 'price' => $faker->randomFloat($nbMaxDecimals = NULL, $min = 0, $max = NULL), 'content' => $faker->text($maxNbChars = 200), 'discount' => $faker->numberBetween($min = 1, $max = 100), 'image' => $faker->file('D:\\laravel\\laravel_totnghiep\\storage\\image', 'D:\\laravel\\laravel_totnghiep\\app\\image', false), 'view' => $faker->numberBetween($min = 0, $max = 1)]);
     }
 }
开发者ID:hoangvu2015,项目名称:laravel_totnghiep,代码行数:12,代码来源:DatabaseSeeder.php

示例10: store

 public function store(Request $request)
 {
     $validator = Validator::make($request->all(), ['name' => 'required|max:100', 'model' => 'max:100', 'category_id' => 'required|array', 'photo' => 'image|max:2048']);
     if (!$validator->fails()) {
         $categories_id = $request->input('category_id');
         $catTitles = "";
         // add title and comma for success message
         foreach ($categories_id as $index => $id) {
             $catTitles .= Category::find($id)->title;
             if ($index + 1 != count($categories_id)) {
                 $catTitles .= ", ";
             }
         }
         $product = Product::create(['name' => $request->input('name'), 'model' => $request->input('model')]);
         $product->categories()->attach($categories_id);
         if ($request->hasFile('photo')) {
             $uploaded_photo = $request->file('photo');
             $extension = $uploaded_photo->getClientOriginalExtension();
             $filename = md5(time()) . '.' . $extension;
             $destinationPath = public_path('img');
             $uploaded_photo->move($destinationPath, $filename);
         }
         $product->photo = $filename;
         $product->save();
         return redirect('products')->with('successMsg', $request->input('name') . ' has been successfully created under : ' . $catTitles);
     } else {
         return redirect()->back()->withErrors($validator)->withInput();
     }
 }
开发者ID:yevta,项目名称:laravel-catalog,代码行数:29,代码来源:ProductController.php

示例11: store

 /**
  * Store a newly created resource in storage.
  *
  * @return Response
  */
 public function store(Request $request)
 {
     //
     if (Auth::check()) {
         # code...
         $rules = ['name' => 'required|string|unique:products', 'price' => 'required|numeric', 'quantity' => 'required|integer', 'category_id' => 'required|integer', 'image_path' => 'required|image'];
         $validator = Validator::make($request->all(), $rules);
         if ($validator->fails()) {
             # code...
             return redirect()->back()->withErrors($validator);
         }
         if ($request->hasFile('image_path')) {
             # code...
             $input = $request->all();
             $image = $input['image_path'];
             $name = '' . $input['name'] . '.png';
             $image = $image->move(public_path() . '/images/products/', studly_case($name));
             $url = "192.168.0.16/images/products/" . studly_case($name);
             //dd($input);
             $product = Product::create(['name' => $input['name'], 'price' => $input['price'], 'quantity' => $input['quantity'], 'category_id' => $input['category_id'], 'image_path' => $url]);
             return redirect('home');
         }
         return redirect()->back()->withErrors('something went wrong');
     }
     return redirect('/');
 }
开发者ID:a-madhukar,项目名称:clubEcommerce,代码行数:31,代码来源:ProductsController.php

示例12: store

 /**
  * Store a newly created resource in storage.
  *
  * @return Response
  */
 public function store(ProductCreateRequest $request)
 {
     $name = $request->Input('name');
     $category_id = $request->Input('category_id');
     $brand_id = $request->Input('brand_id');
     $origin_id = $request->Input('origin_id');
     $qty_inventory = $request->Input('qty_inventory');
     $price = $request->Input('price');
     $content = $request->Input('content');
     $discount = $request->Input('discount');
     //Check fileImage
     if ($request->hasFile('image')) {
         $image = $request->file('image');
         $imagename = time() . '-' . $image->getClientOriginalName();
         $image->move(public_path() . '/image', $imagename);
     } else {
         $imagename = null;
     }
     //Status
     if ($request->Input('status_product') == false) {
         $status_product = 0;
     } else {
         $status_product = 1;
     }
     $data = ['name' => $name, 'category_id' => $category_id, 'brand_id' => $brand_id, 'origin_id' => $origin_id, 'qty_inventory' => $qty_inventory, 'price' => $price, 'content' => $content, 'discount' => $discount, 'image' => $imagename, 'status_product' => $status_product];
     //dd($data);
     Product::create($data);
     //dd($data);
     //$category = Category::find($category_id);//dong loai SP.
     // $category->product()->create($data); //store database.
     return redirect()->route('product.index');
 }
开发者ID:hoangvu2015,项目名称:laravel_totnghiep,代码行数:37,代码来源:ProductController.php

示例13: createProcess

 /**
  * @param Request $request
  * @return $this|\Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
  */
 public function createProcess(Request $request)
 {
     $validator = Validator::make($request->all(), ['product_name' => 'required', 'caption' => 'required', 'description' => 'required']);
     if ($validator->fails()) {
         return redirect()->back()->withErrors($validator)->withInput();
     }
     $file = $request->file('product_name');
     $orginalsize = public_path('uploads/original/');
     $thumbnailsize = public_path('uploads/thumbnail/');
     $filename = str_random(24) . "." . $file->getClientOriginalExtension();
     if (file_exists($filename)) {
         $filename = str_random(24) . "." . $file->getClientOriginalExtension();
     }
     $fileExtension = $file->getClientOriginalExtension();
     $fileSize = $file->getSize();
     if ($fileSize > 51200000) {
         $request->session()->flash('message', 'Sorry file size large');
         return redirect('create_product');
     }
     if ($fileExtension != "jpg" && $fileExtension != "png") {
         $request->session()->flash('message', 'Sorry try jpg or png');
         return redirect('create_product');
     } else {
         Image::make($file)->save($orginalsize . $filename)->resize(150, 150)->save($thumbnailsize . $filename);
         Product::create(['product_name' => $filename, 'caption' => $request->caption, 'description' => $request->description]);
         $request->session()->flash('message', 'Products add success');
         return redirect('view_products');
     }
 }
开发者ID:saidur92,项目名称:Laravel-basic-curd-by-me,代码行数:33,代码来源:productsController.php

示例14: run

 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     Product::create(['product_type_id' => 1, 'unit_id' => 1, 'mix_no' => 100001, 'code' => '100001', 'description' => 'เทป PVC (White)', 'use_serial_no' => Product::USE_SERIAL_NO]);
     Product::create(['product_type_id' => 2, 'unit_id' => 1, 'mix_no' => 100002, 'code' => '100002', 'description' => 'เทป PVC (blue)', 'use_serial_no' => Product::USE_SERIAL_NO]);
     Product::create(['product_type_id' => 1, 'unit_id' => 2, 'mix_no' => 100003, 'code' => '100003', 'description' => 'เทป PVC (Red)', 'use_serial_no' => Product::USE_SERIAL_NO]);
     Product::create(['product_type_id' => 1, 'unit_id' => 2, 'mix_no' => 100004, 'code' => '100004', 'description' => 'เทป PVC (Yellow)', 'use_serial_no' => Product::USE_SERIAL_NO]);
 }
开发者ID:vasitjuntong,项目名称:mixed,代码行数:12,代码来源:ProductSeeder.php

示例15: store

 /**
  * Guarda un nuevo record en nuestra tabla de products
  *
  * @param  ProductRequest  $request -> valida los campos requeridos para crear un nuevo producto
  * @return \Illuminate\Http\Response
  */
 public function store(ProductRequest $request)
 {
     /* creaco una nuevo producto */
     /* $request->all() trae la formación que se ingreso en la forma */
     Product::create($request->all());
     /* redirege a el listado de productos */
     return redirect('products');
 }
开发者ID:angelsalazar,项目名称:plazaapp,代码行数:14,代码来源:AdminProductsController.php


注:本文中的app\Product::create方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。