本文整理汇总了PHP中Faker\Factory::paragraphs方法的典型用法代码示例。如果您正苦于以下问题:PHP Factory::paragraphs方法的具体用法?PHP Factory::paragraphs怎么用?PHP Factory::paragraphs使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Faker\Factory
的用法示例。
在下文中一共展示了Factory::paragraphs方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: run
/**
* Run the seeder.
*
* @return void
*/
public function run()
{
$this->faker = FakerFactory::create('en_GB');
// Returns a random element from an array
function mt_rand_arr($array, $exclude = [])
{
if ($exclude) {
$array = array_diff($array, $exclude);
}
return $array[mt_rand(0, count($array) - 1)];
}
DB::connection()->disableQueryLog();
$this->now = time();
$this->itemConditions = ItemCondition::all();
$this->listingDurations = ListingDuration::all();
$this->command->info('Adding categories');
for ($i = 1; $i <= self::TOTAL_CATEGORIES; $i++) {
$category = new Category();
$category->name = implode(' ', $this->faker->words(2));
$category->slug = str_slug($category->name);
$category->sort = mt_rand(0, 10);
$category->save();
$this->categories[] = $category;
}
foreach ($this->categories as $category) {
if (mt_rand(0, 1)) {
continue;
}
$category->parentCategoryId = mt_rand_arr($this->categories)->categoryId;
$category->save();
}
$this->command->info('Adding users');
for ($i = 1; $i <= self::TOTAL_USERS; $i++) {
$user = new User();
$user->username = $this->faker->userName;
while (User::findByEmail($user->email = $this->faker->email)) {
}
$user->password = Hash::make('password');
$user->verified = true;
$user->joined = mt_rand($this->now - mt_rand(0, 86400 * 200), $this->now);
$user->locale = $this->faker->locale;
$user->currency = $this->faker->currencyCode;
$user->lastLogin = mt_rand($user->joined, $this->now);
$user->save();
//if ($i == 1) $user->grantAdmin();
$this->users[] = $user;
}
if (mustard_loaded('commerce')) {
$this->command->info('Adding postal addresses');
foreach ($this->users as $user) {
for ($i = 0; $i <= mt_rand(1, 3); $i++) {
$postal_address = new \Hamjoint\Mustard\Commerce\PostalAddress();
$postal_address->user()->associate($user);
$postal_address->name = $user->username;
$postal_address->street1 = $this->faker->secondaryAddress;
$postal_address->street2 = $this->faker->streetAddress;
$postal_address->city = $this->faker->city;
$postal_address->county = $this->faker->county;
$postal_address->postcode = $this->faker->postcode;
$postal_address->country = $this->faker->countryCode;
$postal_address->save();
}
}
}
$this->command->info('Adding items');
for ($i = 1; $i <= self::TOTAL_ITEMS; $i++) {
$item = new Item();
$item->seller()->associate(mt_rand_arr($this->users));
$item->condition()->associate($this->itemConditions->random());
$item->name = implode(' ', $this->faker->words(mt_rand(2, 5)));
$item->description = implode("\n\n", $this->faker->paragraphs(2));
$item->auction = mustard_loaded('auctions') ? (bool) mt_rand(0, 1) : false;
$item->quantity = !$item->auction ? mt_rand(1, 100) : 1;
$item->startPrice = $item->biddingPrice = mt_rand(50, 500000) / 100;
$item->reservePrice = mt_rand($item->startPrice * 100, 500000) / 100;
$item->fixedPrice = !$item->auction || !mt_rand(0, 3) ? $item->startPrice + mt_rand(50, 500000) / 100 : 0;
$item->commission = 0.07000000000000001;
$item->duration = $this->listingDurations->random()->duration;
$item->created = mt_rand($item->seller->joined, $this->now);
$item->startDate = mt_rand($item->created, $this->now + 86400 * 14);
$item->endDate = $item->getEndDate();
$item->collectionLocation = $this->faker->city;
$item->paymentOther = mt_rand(0, 1);
$item->returnsPeriod = mt_rand(7, 21);
$item->save();
// Add to categories
for ($ii = 0; $ii < mt_rand(1, 3); $ii++) {
$category = Category::leaves()->get()->random();
try {
$item->categories()->save($category);
} catch (\Exception $e) {
//
}
}
// Add delivery options
//.........这里部分代码省略.........