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


PHP Product::create方法代码示例

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


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

示例1: run

 /**
  * Run product (Ford models) seeds.
  *
  * @return void
  */
 public function run()
 {
     $products = [['product_name' => 'Aerostar'], ['product_name' => 'Aspire'], ['product_name' => 'Bax'], ['product_name' => 'Bronco'], ['product_name' => 'Cmax'], ['product_name' => 'Capri'], ['product_name' => 'Caravan'], ['product_name' => 'Cargo'], ['product_name' => 'ClubWagon'], ['product_name' => 'ConnectTourneo'], ['product_name' => 'Contour'], ['product_name' => 'Cougar'], ['product_name' => 'Courier'], ['product_name' => 'CrownVictoria'], ['product_name' => 'Econoline'], ['product_name' => 'Econovan'], ['product_name' => 'Edge'], ['product_name' => 'Escape'], ['product_name' => 'Escort'], ['product_name' => 'Excursion'], ['product_name' => 'Expedition'], ['product_name' => 'Explorer'], ['product_name' => 'Express'], ['product_name' => 'F150'], ['product_name' => 'F250'], ['product_name' => 'F350'], ['product_name' => 'F450'], ['product_name' => 'F470'], ['product_name' => 'F700'], ['product_name' => 'Fairlane'], ['product_name' => 'Falcon'], ['product_name' => 'Fiesta'], ['product_name' => 'FiveHundrer'], ['product_name' => 'Flex'], ['product_name' => 'Focus'], ['product_name' => 'FocusCMAX'], ['product_name' => 'Freestar'], ['product_name' => 'Freestyle'], ['product_name' => 'Fusion'], ['product_name' => 'Galaxy'], ['product_name' => 'Granada'], ['product_name' => 'GrandCMAX'], ['product_name' => 'GT'], ['product_name' => 'Ka'], ['product_name' => 'Kuga'], ['product_name' => 'LTD'], ['product_name' => 'Maverick'], ['product_name' => 'Mercury'], ['product_name' => 'Mondeo'], ['product_name' => 'Mustang'], ['product_name' => 'Orion'], ['product_name' => 'Probe'], ['product_name' => 'Puma'], ['product_name' => 'Ranger'], ['product_name' => 'SMAX'], ['product_name' => 'Scorpio'], ['product_name' => 'Sierra'], ['product_name' => 'Sportka'], ['product_name' => 'Streetka'], ['product_name' => 'Superduty'], ['product_name' => 'Taunus'], ['product_name' => 'Taurus'], ['product_name' => 'Tempo'], ['product_name' => 'Thunderbird'], ['product_name' => 'Tourneo'], ['product_name' => 'Transit'], ['product_name' => 'TransitConnect'], ['product_name' => 'Windstar']];
     foreach ($products as $product) {
         Product::create($product);
     }
 }
开发者ID:skygravity,项目名称:laravel-closure-table,代码行数:12,代码来源:ProductsTableSeeder.php

示例2: action_parse

 public function action_parse()
 {
     $source_file_content = \Storage::get('coolbaby_11082015.csv');
     $source_file_rows = explode("\n", $source_file_content);
     array_shift($source_file_rows);
     if (empty($source_file_rows)) {
         $this->error('Массив пуст');
         return;
     }
     $this->output->progressStart(count($source_file_rows));
     foreach ($source_file_rows as $row) {
         $row = trim($row);
         if (empty($row)) {
             continue;
         }
         $fields = explode(';', $row);
         $product_model = \App\Models\Product::create(['code' => trim($fields[0]), 'article' => trim($fields[1]), 'name' => trim($fields[2]), 'category_name' => trim($fields[3]), 'brand' => trim($fields[4]), 'price_2' => trim($fields[5]), 'price_1' => trim($fields[6]), 'catalog_id' => 2]);
         $source_url = 'http://' . substr(trim($fields[7]), 0, -4) . '_big.jpg';
         $media_model = new \App\Models\Media();
         $media_model->product_id = $product_model->id;
         $media_model->source_url = $source_url;
         $media_model->save();
         $this->output->progressAdvance();
     }
     $this->output->progressFinish();
 }
开发者ID:serovvitaly,项目名称:kotik,代码行数:26,代码来源:CoolBabyCommand.php

示例3: run

 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     $faker = Faker\Factory::create();
     foreach (range(1, 50) as $index) {
         Product::create(['title' => $faker->sentence, 'description' => $faker->paragraph(4), 'primary_image_path' => 'main_image_' . rand(1, 4) . '.jpeg', 'delivery' => $faker->boolean(50), 'pickup' => $faker->boolean(50), 'free' => $faker->boolean(50), 'price' => $faker->numberBetween(0, 100), 'user_id' => rand(1, 29), 'university_id' => rand(2, 149)]);
     }
 }
开发者ID:shwetasabne,项目名称:StudentBarter,代码行数:12,代码来源:ProductTableSeeder.php

示例4: run

 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     $faker = Faker::create();
     $categories = Categories::where('parent_id', '>=', 0)->get();
     $baseUrl = 'http://7xkn9n.com1.z0.glb.clouddn.com/img/';
     $string = file_get_contents(__DIR__ . "/../data/products.json");
     $products = json_decode($string, true);
     $cate_ids = [];
     foreach ($categories as $category) {
         $cate_ids[] = $category->id;
     }
     foreach ($products as $productData) {
         try {
             $name = $productData['meta']['title'];
             $content = '';
             if (isset($productData['content'])) {
                 $content = str_replace('<h2 class="title">百科词条</h2>', '', $productData['content']);
             }
             $klass = $productData['meta']['class']['text'];
             $category = Categories::where('name', $klass)->get();
             $description = substr($content, 0, 100);
             $cid = $faker->randomElement($cate_ids);
             if ($category->count() == 1) {
                 $cid = $category[0]->id;
             }
             $pieces = preg_split("/\\//i", $productData['meta']['image']);
             $product = Product::create(['name' => $name, 'slug' => $name, 'description' => $description, 'keywords' => $klass, 'cover' => $baseUrl . $pieces[count($pieces) - 1], 'category_id' => $cid, 'user_id' => 1]);
             $detailTopic = Topic::create(['title' => $name, 'slug' => $name, 'product_id' => $product->id, 'user_id' => 1, 'keywords' => $name, 'description' => $description, 'content' => $content, 'is_product_detail_topic' => true]);
             $product->detail_topic_id = $detailTopic->id;
             $product->save();
         } catch (Exception $e) {
             throw $e;
         }
     }
 }
开发者ID:jiketao,项目名称:jiketao-laravel,代码行数:40,代码来源:ProductsTableSeeder.php

示例5: run

 public function run()
 {
     DB::table('products')->delete();
     Product::create(array('id' => '1', 'name' => 'Шина Gislaved Nord Frost 100 185 / 65 R15 92T XL', 'description' => 'Летная шина Urban Speed идеально подходит как для мегаполисов, так и для небольших городов, обладая прекрасными рабочими характеристиками и сцеплением, она станет  надежным спутником  для автомобилей компакт и среднего классов.', 'count' => '159', 'price' => '1000', 'weight' => '0.1', 'width' => '5', 'height' => '2.4', 'length' => '5'));
     Product::create(array('id' => '2', 'name' => 'Шина Pirelli Formula Energy 175 / 65 R14 82T', 'description' => 'Шины Pirelli разрабатываются с целью максимально раскрыть возможности автомобиля и при этом обеспечить отличную управляемость и устойчивость на любом дорожном покрытии. При экстремальных температурах, погодных условиях и при любом стиле вождения качественные шины Pirelli остаются оптимальным выбором среди экспертов и автолюбителей по всему миру. Многолетний опыт разработки новых технологий для производства шин и постоянная кропотливая исследовательская работа инженеров Pirelli позволили компании занять ведущее место в производстве высококлассных шин для мирового рынка. Новое поколение инноваций от Pirelli заключается в разработке материалов и технологий для улучшения технических и экологических свойств и создания новых качественных характеристик шин.', 'count' => '137', 'price' => '2000', 'weight' => '0.1', 'width' => '5', 'height' => '2.4', 'length' => '5'));
     Product::create(array('id' => '3', 'name' => 'Шина Nokian Nordman SX 165 / 70 R13 79T', 'description' => 'Прочная и экономичная летняя шина, которая подходит для семейных автомобилей малого и среднего классов. Она легко вращается, при её использовании расходуется меньше топлива.', 'count' => '68', 'price' => '3000', 'weight' => '0.1', 'width' => '5', 'height' => '2.4', 'length' => '5'));
 }
开发者ID:artyomich,项目名称:laravel,代码行数:7,代码来源:ProductsTableSeeder.php

示例6: store

 /**
  * Store a newly created resource in storage.
  *
  * @return Response
  */
 public function store(Request $request)
 {
     $this->validate($request, ['name' => 'required', 'description' => 'required', 'category_id' => 'required', 'purchase_price' => 'required', 'price' => 'required']);
     Product::create($request->all());
     Session::flash('flash_message', 'Product added!');
     return redirect('backoffice/products');
 }
开发者ID:AntonBeletsky,项目名称:laravel_minishop,代码行数:12,代码来源:ProductsController.php

示例7: store

 /**
  * Store a newly created Product in database.
  *
  * @return Response
  */
 public function store(ProductRequest $request)
 {
     /**
      * Take all inputs except image, store image in seperate variable
      *
      * @var Array
      */
     $input = $request->except('image');
     $image = $request->file('image');
     if ($image != null) {
         // Picture name will be same as SKU
         $name = $input['sku'];
         // Extenstion of original picture
         $extension = '.' . $image->getClientOriginalExtension();
         // Set paths for full image and thumbnail
         $imagePath = 'img/' . $name . $extension;
         $thumbnailPath = 'img/thumbs/' . $name . $extension;
         // Save original picture
         \Image::make($image->getRealPath())->save(public_path($imagePath));
         // Save resized thumbnail
         \Image::make($image->getRealPath())->resize(300, null, function ($constraint) {
             $constraint->aspectRatio();
         })->save(public_path($thumbnailPath));
     } else {
         // Set default 'No image avaliable' images
         $imagePath = self::DEFAULT_IMG;
         $thumbnailPath = self::DEFAULT_IMG;
     }
     // Create Product model and save pictures
     $product = Product::create($input);
     $product->image = $imagePath;
     $product->image_thumb = $thumbnailPath;
     $product->save();
     return redirect(route('AdminProductIndex'));
 }
开发者ID:catchup-forks,项目名称:gameshop,代码行数:40,代码来源:ProductController.php

示例8: store

 public function store(UserAuth $user)
 {
     $this->validateJson(request()->all(), $rules = ['title' => 'required|title|min:4|max:60', 'subtitle' => 'title|min:4|max:120', 'description' => 'required', 'price' => 'required|numeric', 'stock_initial' => 'integer', 'stock_available' => 'integer', 'starts' => 'required|date_format:d/m/Y', 'ends' => 'required|date_format:d/m/Y', 'is_active' => 'required|boolean']);
     $data = reqOnlyIfExists(array_keys($rules));
     $data['seller_id'] = $user->id;
     $data['starts'] = \DateTime::createFromFormat('d/m/Y', $data['starts']);
     $data['ends'] = \DateTime::createFromFormat('d/m/Y', $data['ends']);
     // price:
     if ($data['price'] < 0) {
         $this->errorValidateJson(['price' => 'price must be positive']);
     }
     // stock:
     if (isset($data['stock_available']) && !isset($data['stock_initial'])) {
         $data['stock_initial'] = $data['stock_available'];
     }
     if (isset($data['stock_initial']) && !isset($data['stock_available'])) {
         $data['stock_available'] = $data['stock_initial'];
     }
     if (isset($data['stock_initial']) && $data['stock_initial'] < 0) {
         $this->errorValidateJson(['stock_initial' => 'quantity must be zero or positive integer']);
     }
     if (isset($data['stock_initial']) && $data['stock_initial'] < $data['stock_available']) {
         $this->errorValidateJson(['stock_initial' => 'stock initial must be greater than stock available']);
     }
     // start / end:
     if ($data['starts'] >= $data['ends']) {
         $this->errorValidateJson(['starts' => 'start date must be before end date']);
     }
     $starts2 = clone $data['starts'];
     if ($starts2->sub(new \DateInterval('PT1H')) < new \DateTime()) {
         $this->errorValidateJson(['starts' => 'start date must start from present']);
     }
     return \App\Models\Product::create($data);
 }
开发者ID:sebalb,项目名称:shopapp,代码行数:34,代码来源:Product.php

示例9: store

 /**
  * Store items in database.
  *
  * @param CreateProduct $request
  * @return \Illuminate\Http\RedirectResponse
  */
 public function store(CreateProduct $request)
 {
     $data = $this->proccesData($request);
     $product = Product::create($data);
     $product->size()->attach($data['size_id']);
     Session::flash('flash_message', 'Product successfully added!');
     return redirect()->back();
 }
开发者ID:raylight75,项目名称:cms,代码行数:14,代码来源:ArticlesController.php

示例10: run

 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     DB::table('products')->truncate();
     $faker = Faker::create();
     foreach (range(1, 20) as $index) {
         Product::create(['name' => 'Product ' . $index, 'subindustry_id' => Subindustry::all()->get($faker->numberBetween(1, 20))->id]);
     }
 }
开发者ID:sagaciresearch,项目名称:adtracking,代码行数:13,代码来源:ProductTableSeeder.php

示例11: run

 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     $objs = factory(Product::class, 30)->make();
     Product::truncate();
     foreach ($objs as $var) {
         Product::create($var->toArray());
     }
 }
开发者ID:guduchango,项目名称:limoncello,代码行数:13,代码来源:ProductsTableSeeder.php

示例12: run

 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     DB::table('products')->truncate();
     $products = [['category_id' => 1, 'name' => 'Tex-Mex Nachos', 'slug' => 'tex-mex-nachos', 'description' => 'Platter of Ncho Chips Topped with Sautees Beef, Cheese Saucce and Flavored Dressing.', 'price' => '250', 'picture' => 'http://restoko.aindong.com/uploads/image1.jpeg'], ['category_id' => 1, 'name' => 'Java Chicken Wings', 'slug' => 'java-chicken-wings', 'description' => 'Deep Fried 3 pieces Chicken wings Coated with BBQ Sauce Served with Crudities in Java Aioli', 'price' => '140', 'picture' => 'http://restoko.aindong.com/uploads/image2.jpeg'], ['category_id' => 2, 'name' => 'Javalicious Braised Short ribs BBQ', 'slug' => 'javalicious-braised-short-ribs-bbq', 'description' => 'Slow cooked Braised Short ribs Served with Com and Carrots Mashed Potatoes with Java BBQ Sauce', 'price' => '275', 'picture' => 'http://restoko.aindong.com/uploads/image3.jpeg'], ['category_id' => 2, 'name' => 'Grilled Pork Steak', 'slug' => 'grilled-pork-steak', 'description' => 'Marinated Pork Steak Grilled to Perfection Served with Buttered Vegetables, Rice and Java Gravy', 'price' => '280', 'picture' => 'http://restoko.aindong.com/uploads/image4.jpeg'], ['category_id' => 2, 'name' => 'Herb and Nut Crusted fish Fillet', 'slug' => 'product-5', 'description' => 'Crispy Pan- Fried Fish fillet  Coated with Herbs and Nuts Served with Green Salad and Rice', 'price' => '190', 'picture' => 'http://restoko.aindong.com/uploads/image5.jpeg'], ['category_id' => 3, 'name' => 'Combo 1', 'slug' => 'combo-1', 'description' => 'Breaded prok with MushrooM Gravy, Rice, Coleslaw, Blue Lemonade, Free Soup', 'price' => '79', 'picture' => 'http://restoko.aindong.com/uploads/image6.jpeg'], ['category_id' => 3, 'name' => 'Combo 2', 'slug' => 'combo-2', 'description' => 'Grilled chicken Breast Inasal,Coleslaw, Rice, Blue Lemonade, Free Soup', 'price' => '79', 'picture' => 'http://restoko.aindong.com/uploads/image7.jpeg'], ['category_id' => 3, 'name' => 'Combo 3', 'slug' => 'combo-3', 'description' => 'Stir-Fried Beef and Vegetables Salpicao, Coleslaw, Rice, Blue Lemonade, Free Soup', 'price' => '99', 'picture' => 'http://restoko.aindong.com/uploads/image8.jpeg'], ['category_id' => 4, 'name' => 'Java Caezar Salad', 'slug' => 'product-7', 'description' => 'Our Version of Caesar salad, Lettuce, Bacon, Croutons, Parmesan Cheese Served with Homemade Caezar Dressing', 'price' => '155', 'picture' => 'http://restoko.aindong.com/uploads/image9.jpeg'], ['category_id' => 4, 'name' => 'Java Garden Salad', 'slug' => 'product-7', 'description' => 'Lettuce, Tomato, Turnips, Carrots, Cucumber, Bell Peppers Served with Honey Orange Vinaigratte', 'price' => '115', 'picture' => 'http://restoko.aindong.com/uploads/image10.jpeg'], ['category_id' => 4, 'name' => 'Java Chicken Pizza7', 'slug' => 'product-7', 'description' => 'Marinated Grilled chicken with Creamy White Sauce over Thinly Baked Crust', 'price' => '165', 'picture' => 'http://restoko.aindong.com/uploads/image11.jpeg'], ['category_id' => 12, 'name' => 'Blowjob', 'slug' => 'product-7', 'description' => '', 'price' => '100', 'picture' => ''], ['category_id' => 12, 'name' => 'Blow Job Revenge', 'slug' => 'product-7', 'description' => '', 'price' => '100', 'picture' => ''], ['category_id' => 12, 'name' => '4th of July Tooter', 'slug' => 'product-7', 'description' => '', 'price' => '100', 'picture' => ''], ['category_id' => 12, 'name' => 'Organism', 'slug' => 'product-7', 'description' => '', 'price' => '100', 'picture' => ''], ['category_id' => 12, 'name' => 'Flaming Ferrari', 'slug' => 'product-7', 'description' => '', 'price' => '100', 'picture' => '']];
     foreach ($products as $product) {
         \App\Models\Product::create($product);
     }
 }
开发者ID:restoko,项目名称:restoko-api,代码行数:13,代码来源:ProductTableSeeder.php

示例13: store

 public function store(ProductCreateRequest $request)
 {
     $input = $request->except('categories');
     $input = $this->uploadPicture($input);
     $product = Product::create($input);
     $product->categories()->attach($request->categories);
     return redirect('admin/products');
 }
开发者ID:ninjamonz,项目名称:laravel_catalog_example,代码行数:8,代码来源:ProductsController.php

示例14: run

 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     Model::unguard();
     DB::table('products')->delete();
     Product::create(array('name' => 'spam', 'price' => 4.65, 'in_stock' => true));
     Product::create(array('name' => 'spam lite', 'price' => 4.95, 'in_stock' => true));
     Product::create(array('name' => 'spam reduced sodium', 'price' => 4.95, 'in_stock' => true));
     Model::reguard();
 }
开发者ID:senorbacon,项目名称:toy_api,代码行数:14,代码来源:ProductTableSeeder.php

示例15: store

 /**
  * Store a newly created resource in storage.
  *
  * @return Response
  */
 public function store(Products $request)
 {
     $all = $request->all();
     $all['user_id'] = Auth::user()->id;
     $all['image'] = $this->upload($all['image']);
     Product::create($all);
     Session::flash('flash_message', 'Product added!');
     return redirect('products-grid');
 }
开发者ID:pavhov93,项目名称:blog2,代码行数:14,代码来源:ProductsController.php


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