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