本文整理匯總了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));
}
}