Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #### Migration #####
- Schema::create('polls', function (Blueprint $table) {
- $table->increments('id');
- $table->string('title', 200);
- $table->timestamps();
- });
- Schema::create('questions', function (Blueprint $table) {
- $table->increments('id');
- $table->string('title', 200);
- $table->mediumText('question');
- $table->unsignedInteger('poll_id');
- $table->timestamps();
- });
- Schema::create('answers', function (Blueprint $table) {
- $table->increments('id');
- $table->mediumText('answer');
- $table->unsignedInteger('question_id');
- $table->timestamps();
- });
- #### Database Seeder ######
- factory(App\User::class, 5)->create();
- factory(App\Poll::class, 10)->create();
- factory(App\Question::class, 50)->create();
- factory(App\Answer::class, 500)->create();
- #### Poll Factory #####
- $factory->define(App\Poll::class, function (Faker $faker) {
- return [
- 'title' => $faker->realText(50),
- ];
- });
- $factory->define(App\Question::class, function (Faker $faker) {
- $poll_ids = DB::table('polls')->pluck('id')->all();
- return [
- 'title' => $faker->realText(50),
- 'question' => $faker->realText(500),
- 'poll_id' => $faker->randomElement($poll_ids),
- ];
- });
- $factory->define(App\Answer::class, function (Faker $faker) {
- $question_ids = DB::table('questions')->pluck('id')->all();
- return [
- 'answer' => $faker->realText(500),
- 'question_id' => $faker->randomElement($question_ids),
- ];
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement