add seeder migration
This commit is contained in:
parent
1377fbb89a
commit
c6c8d18ae2
|
@ -0,0 +1,57 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
use app\models\Blog;
|
||||||
|
use app\models\Comment;
|
||||||
|
use app\models\Company;
|
||||||
|
use app\models\Material;
|
||||||
|
use app\models\Subscription;
|
||||||
|
use app\models\User;
|
||||||
|
use yii\db\Migration;
|
||||||
|
|
||||||
|
class m0000001_seed extends Migration
|
||||||
|
{
|
||||||
|
public function safeUp()
|
||||||
|
{
|
||||||
|
$gen = new \Faker\Generator();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Тут я не сильно оптимизировал под скорость т.к. это всего лишь 3 итерации
|
||||||
|
* и это не апи а консольная команда
|
||||||
|
*/
|
||||||
|
|
||||||
|
for ($i = 0; $i != 2; $i++) {
|
||||||
|
$user = new User();
|
||||||
|
$user->name = $gen->firstName();
|
||||||
|
$user->login = 'user_' + $i;
|
||||||
|
$user->phone = $gen->phoneNumber();
|
||||||
|
$user->passHash = Yii::$app->getSecurity()->generatePasswordHash('pass_' + $i);
|
||||||
|
$user->save();
|
||||||
|
|
||||||
|
$material = new Material();
|
||||||
|
$material->title = $gen->words(10, true);
|
||||||
|
$material->content = $gen->paragraph();
|
||||||
|
$material->blog_id = 0;
|
||||||
|
$material->save();
|
||||||
|
|
||||||
|
$company = new Company();
|
||||||
|
$company->title = $gen->words(2, true);
|
||||||
|
$company->website = "https://" . $gen->word() . '.com';
|
||||||
|
$company->address = $gen->address();
|
||||||
|
$company->save();
|
||||||
|
|
||||||
|
$blog = new Blog();
|
||||||
|
$blog->save();
|
||||||
|
|
||||||
|
$subscription = new Subscription();
|
||||||
|
$subscription->user_id = $user->id;
|
||||||
|
$subscription->blog_id = $blog->id;
|
||||||
|
$subscription->save();
|
||||||
|
|
||||||
|
$comment = new Comment();
|
||||||
|
$comment->material_id = $material->id;
|
||||||
|
$comment->user_id = $user->id;
|
||||||
|
$comment->content = $gen->paragraph();
|
||||||
|
$comment->save();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue