Created
October 8, 2016 22:58
-
-
Save artemrogov/db2161e424fbeb6c77fa45f1d0fb8144 to your computer and use it in GitHub Desktop.
Laravel: Создание фабрик автозаполнения тестировочными данными - фабрики
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$factory->define(App\Post::class, function (Faker\Generator $faker) { | |
return [ | |
'title' => $faker->title, | |
'body' => $faker->paragraph(10), | |
'user_id'=>function () { | |
return factory(App\User::class)->create()->id; | |
} | |
]; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
создается фабрика, постов, каждый пост связывается с пользователем.
Можно вызвать в тинкере так:
factory('App\Post',<кол-во генерируемых постов>')->create();