本文整理汇总了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);
}
}
}
});
}
示例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));
}
}