本文整理汇总了PHP中app\models\Category::inRandomOrder方法的典型用法代码示例。如果您正苦于以下问题:PHP Category::inRandomOrder方法的具体用法?PHP Category::inRandomOrder怎么用?PHP Category::inRandomOrder使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类app\models\Category
的用法示例。
在下文中一共展示了Category::inRandomOrder方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: run
/**
* Run the database seeds.
*
* @return void
*/
public function run()
{
factory(Category::class, random_int(1, 5))->create();
factory(Category::class, random_int(1, 10))->make()->each(function (Category $category) {
$category->parent_id = Category::inRandomOrder()->first()->id;
$category->save();
});
}
示例2: function
$file_name = 'currency-iso.xml';
$storage = Storage::disk('local');
if (!$storage->exists($file_name)) {
$storage->put($file_name, file_get_contents($url));
}
$xml = simplexml_load_string($storage->get($file_name));
$json = json_encode($xml);
$array = json_decode($json, true);
$currencies = $array['CcyTbl']['CcyNtry'];
}
$index = array_rand($currencies, 1);
return ['name' => $currencies[$index]['CcyNm'], 'code' => $currencies[$index]['Ccy'], 'number' => $currencies[$index]['CcyNbr'], 'unit' => $currencies[$index]['CcyMnrUnts'] === 'N.A.' ? 0 : $currencies[$index]['CcyMnrUnts']];
});
$factory->define(Product::class, function (Faker\Generator $faker) {
$content = $faker->paragraphs(random_int(1, 16), true);
$description = str_limit(trim(strip_tags(nl2br($content))), 156);
$name = $faker->name;
return ['name' => $name, 'description' => $description, 'content' => $content, 'slug' => str_slug($name), 'price' => random_int(1, 10000000), 'published_at' => Carbon::now(), 'category_id' => Category::inRandomOrder()->first()->id, 'currency_id' => Currency::inRandomOrder()->first()->id];
});
$factory->define(Category::class, function (Faker\Generator $faker) {
$content = $faker->paragraphs(random_int(1, 16), true);
$description = str_limit(trim(strip_tags(nl2br($content))), 156);
$name = $faker->word;
return ['name' => $name, 'description' => $description, 'content' => $content, 'slug' => str_slug($name), 'published_at' => Carbon::now()];
});
$factory->define(Attachment::class, function (Faker\Generator $faker) {
$url = 'https://source.unsplash.com/random';
$name = str_random(16) . '.jpg';
$property = app(\App\Services\ImageService::class)->make($url, $name);
return ['file' => $name, 'dick' => 'local', 'property' => $property];
});