本文整理汇总了PHP中Forum::connection方法的典型用法代码示例。如果您正苦于以下问题:PHP Forum::connection方法的具体用法?PHP Forum::connection怎么用?PHP Forum::connection使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Forum
的用法示例。
在下文中一共展示了Forum::connection方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: run
/**
* Run Method.
*/
public function run()
{
Forum::connection()->query('SET FOREIGN_KEY_CHECKS = 0');
$faker = Faker\Factory::create('ru_RU');
// Заполнение разделов
$data = [];
for ($i = 0; $i < 15; $i++) {
$data[] = ['sort' => $i, 'parent_id' => $i < 4 ? 0 : rand(1, 4), 'title' => $faker->realText(rand(20, 30)), 'description' => $faker->realText(rand(30, 50)), 'closed' => $i % 5 ? 0 : 1, 'created_at' => $faker->dateTimeBetween('-1 month')->format('Y-m-d H:i:s')];
}
Forum::connection()->query('TRUNCATE forums');
$table = $this->table('forums');
$table->insert($data)->save();
// Заполнение тем
$data = [];
for ($i = 0; $i < 100; $i++) {
$data[] = ['forum_id' => rand(1, 15), 'user_id' => rand(1, 5), 'title' => $faker->realText(rand(25, 50)), 'note' => $i % 3 ? $faker->realText(rand(30, 100)) : '', 'closed' => $i % 5 ? 0 : 1, 'locked' => $i % 6 ? 0 : 1, 'created_at' => $faker->dateTimeBetween('-1 month')->format('Y-m-d H:i:s')];
}
Topic::connection()->query('TRUNCATE topics');
$table = $this->table('topics');
$table->insert($data)->save();
// Заполнение сообщений
$data = [];
for ($i = 0; $i < 1000; $i++) {
$data[] = ['forum_id' => rand(1, 15), 'topic_id' => rand(1, 50), 'user_id' => rand(1, 5), 'text' => $faker->realText(rand(50, 500)), 'ip' => $faker->ipv4, 'brow' => App::getUserAgent($faker->userAgent), 'created_at' => $faker->dateTimeBetween('-1 month')->format('Y-m-d H:i:s')];
}
Post::connection()->query('TRUNCATE posts');
$table = $this->table('posts');
$table->insert($data)->save();
Forum::connection()->query('SET FOREIGN_KEY_CHECKS = 1');
}
示例2: run
/**
* Run Method.
*/
public function run()
{
User::connection()->query('SET FOREIGN_KEY_CHECKS = 0');
$data = [];
$genders = ['male', 'female'];
$logins = ['admin', 'moder', 'user', 'guest', 'banned'];
$faker = Faker\Factory::create('ru_RU');
foreach ($logins as $login) {
$gender = $genders[array_rand($genders)];
$data[] = ['login' => $login, 'password' => password_hash($login, PASSWORD_BCRYPT), 'email' => $faker->freeEmail, 'gender' => $gender, 'level' => $login, 'name' => $faker->firstName($gender), 'country' => $faker->country, 'city' => $faker->city, 'info' => $faker->realText(rand(30, 100)), 'phone' => $faker->phoneNumber, 'birthday' => $faker->date('d-m-Y'), 'created_at' => $faker->dateTimeBetween('-3 year')->format('Y-m-d H:i:s')];
}
User::connection()->query('TRUNCATE users');
$table = $this->table('users');
$table->insert($data)->save();
Forum::connection()->query('SET FOREIGN_KEY_CHECKS = 1');
}