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


PHP Attribute::all方法代码示例

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


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

示例1: run

 public function run()
 {
     $this->trancate();
     $faker = Faker\Factory::create();
     $languages = Language::all();
     $products = Product::all();
     $attributes = Attribute::all();
     $attributes_options = array();
     foreach ($languages as $language) {
         $options = DB::table('attributes_options')->whereLanguageId($language->id)->get();
         $options = new Illuminate\Database\Eloquent\Collection($options);
         $options = $options->lists("options", 'attribute_id');
         $attributes_options[$language->id] = $options;
     }
     $attributes_key = $attributes->modelKeys();
     $products->each(function ($product) use($attributes_key, $languages, $faker, $attributes_options) {
         $count_to_insert = rand(0, rand(0, count($attributes_key) - 1));
         for ($i = 1; $i <= $count_to_insert; $i++) {
             foreach ($languages as $language) {
                 $attribute_id = $attributes_key[rand(0, count($attributes_key) - 1)];
                 $options = $attributes_options[$language->id][$attribute_id];
                 $tokens = explode("|", $options);
                 try {
                     DB::table('products_to_attributes')->insert(array('product_id' => $product->id, 'language_id' => $language->id, 'attribute_id' => $attribute_id, 'value' => $tokens[rand(0, count($tokens) - 1)]));
                 } catch (Exception $x) {
                     var_dump($x);
                 }
             }
         }
     });
 }
开发者ID:pda-code,项目名称:eshop-angular-laravel,代码行数:31,代码来源:Products_Attributes_Seeder.php

示例2: run

 public function run()
 {
     $this->trancate();
     $languages = Language::all();
     $categories = Category::all()->toArray();
     $attributes = Attribute::all()->toArray();
     //Insert product
     for ($i_product = 1; $i_product < 1000; $i_product++) {
         $product_id = DB::table('products')->insertGetId(array('model' => 'Model ' . $i_product, 'tax_class_id' => rand(1, 2), 'weight_class_id' => rand(1, 4), 'length_class_id' => rand(1, 3), 'image' => 'catalog/demo/product/product (' . rand(1, 86) . ').jpg', 'price' => rand(10, 200), 'stock_status_id' => rand(1, 4), 'manufacturer_id' => rand(1, 6)));
         //product image
         $images_count = rand(0, 5);
         for ($i = 0; $i < $images_count; $i++) {
             DB::table('products_image')->insert(array('product_id' => $product_id, 'image' => 'catalog/demo/product/product (' . rand(1, 86) . ').jpg'));
         }
         foreach ($languages as $language) {
             DB::table('products_description')->insert(array('product_id' => $product_id, 'language_id' => $language->id, 'name' => 'Product ' . $product_id, 'description' => '#' . $product_id . ' Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.'));
         }
         //product reward
         DB::table('products_reward')->insert(array('product_id' => $product_id, 'customer_group_id' => 1, 'points' => $product_id));
     }
 }
开发者ID:pda-code,项目名称:eshop-angular-laravel,代码行数:21,代码来源:Products_Seeder.php


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