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


PHP Product::categories方法代码示例

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


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

示例1: store

 public function store(Request $request)
 {
     $input = $request->json()->all();
     unset($input['categories']);
     $product = new Product($input);
     $product->save();
     if (($categories = $request->json()->get('categories')) && !empty($categories)) {
         if (is_string($categories)) {
             $categories = explode(',', $categories);
         }
         $product->categories()->attach($categories);
     }
     $product->load('categories');
     return response()->created($product);
 }
开发者ID:kshar1989,项目名称:dianpou,代码行数:15,代码来源:ProductController.php

示例2: upsertProduct


//.........这里部分代码省略.........
     if (isset($data['uom'])) {
         $product->uom = $data['uom'];
     }
     if (isset($data['serving_size_uom'])) {
         $product->serving_size_uom = $data['serving_size_uom'];
     }
     if (isset($data['mpc'])) {
         $product->mpc = $data['mpc'];
     }
     if (isset($data['broker_contact'])) {
         $product->broker_contact = $data['broker_contact'];
     }
     if (isset($data['gtin'])) {
         $product->gtin = $data['gtin'];
     }
     $product->is_halal = isset($data['is_halal']) ? 1 : 0;
     $product->is_organic = isset($data['is_organic']) ? 1 : 0;
     $product->is_kosher = isset($data['is_kosher']) ? 1 : 0;
     if (isset($data['calc_size'])) {
         $product->calc_size = $data['calc_size'];
     }
     if (isset($data['calculation_size_uom'])) {
         $product->calculation_size_uom = $data['calculation_size_uom'];
     }
     if (isset($data['calories'])) {
         $product->calories = $data['calories'];
     }
     if (isset($data['calories_from_fat'])) {
         $product->calories_from_fat = $data['calories_from_fat'];
     }
     if (isset($data['protein'])) {
         $product->protein = $data['protein'];
     }
     if (isset($data['carbs'])) {
         $product->carbs = $data['carbs'];
     }
     if (isset($data['fibre'])) {
         $product->fibre = $data['fibre'];
     }
     if (isset($data['sugar'])) {
         $product->sugar = $data['sugar'];
     }
     if (isset($data['total_fat'])) {
         $product->total_fat = $data['total_fat'];
     }
     if (isset($data['saturated_fats'])) {
         $product->saturated_fats = $data['saturated_fats'];
     }
     if (isset($data['sodium'])) {
         $product->sodium = $data['sodium'];
     }
     if (isset($data['product_image'])) {
         $product->product_image = $data['product_image'];
     }
     if (isset($data['description'])) {
         $product->description = $data['description'];
     }
     if (isset($data['preparation'])) {
         $product->preparation = $data['preparation'];
     }
     if (isset($data['ingredient_deck'])) {
         $product->ingredient_deck = $data['ingredient_deck'];
     }
     if (isset($data['features_benefits'])) {
         $product->features_benefits = $data['features_benefits'];
     }
     if (isset($data['allergen_disclaimer'])) {
         $product->allergen_disclaimer = $data['allergen_disclaimer'];
     }
     if (isset($data['net_weight'])) {
         $product->net_weight = $data['net_weight'];
     }
     if (isset($data['gross_weight'])) {
         $product->gross_weight = $data['gross_weight'];
     }
     if (isset($data['tare_weight'])) {
         $product->tare_weight = $data['tare_weight'];
     }
     if (isset($data['serving_size'])) {
         $product->serving_size = $data['serving_size'];
     }
     if (isset($data['vendor_logo'])) {
         $product->vendor_logo = $data['vendor_logo'];
     }
     if (isset($data['pos_pdf'])) {
         $product->pos_pdf = $data['pos_pdf'];
     }
     //$product->published = (isset($data['published']) ? 1 : 0);
     $product->published = $data['published'];
     // Sync allergens
     if (isset($data['allergens'])) {
         $product->allergens()->sync($data['allergens']);
     }
     // Sync categories
     if (isset($data['categories'])) {
         $product->categories()->sync($data['categories']);
     }
     $product->save();
     return $product;
 }
开发者ID:gabwhite,项目名称:fsh,代码行数:101,代码来源:DataAccessLayer.php


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