當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。