function questions()
 {
     $faker = Faker::create();
     foreach (range(0, 10) as $i) {
         Question::create(['body' => $faker->paragraph]);
     }
 }
 /**
  * Store a newly created resource in storage.
  *
  * @return Response
  */
 public function store(Requests\CreateQuestionRequest $request)
 {
     $question = Question::create($request->all());
     //required answer
     $answer_description_1 = $request->answer_description_1;
     $answer_is_correct_1 = $request->answer_is_correct_1;
     $question->answers()->create(['description' => $answer_description_1, 'is_correct' => $answer_is_correct_1]);
     // required answer
     $answer_description_2 = $request->answer_description_2;
     $answer_is_correct_2 = $request->answer_is_correct_2;
     $question->answers()->create(['description' => $answer_description_2, 'is_correct' => $answer_is_correct_2]);
     // optional answer
     $answer_description_3 = $request->answer_description_3;
     $answer_is_correct_3 = $request->answer_is_correct_3;
     if (isset($answer_description_3) && isset($answer_is_correct_3)) {
         $question->answers()->create(['description' => $answer_description_3, 'is_correct' => $answer_is_correct_3]);
     }
     // optional answer
     $answer_description_4 = $request->answer_description_4;
     $answer_is_correct_4 = $request->answer_is_correct_4;
     if (isset($answer_description_4) && isset($answer_is_correct_4)) {
         $question->answers()->create(['description' => $answer_description_4, 'is_correct' => $answer_is_correct_4]);
     }
     \Session::flash('success', 'The question is successfully created.');
     return redirect('questions');
 }
 public function store(QuestionRequest $request)
 {
     $question = Request::only(['name', 'body']);
     $answers = Request::only(['answer_name', 'answer_info']);
     $my_question = Question::create($question);
     return redirect('questions');
 }
Exemple #4
0
 public function post_write(Request $request)
 {
     $this->authorize('qna-write');
     $request->merge(['writer_id' => Auth::user()->id]);
     $q = Question::create($request->all());
     return redirect("qs/{$q->id}");
 }
 public function store(QuestRequest $request)
 {
     $quest = Question::create($request->all());
     $quest->section()->attach($request->input('section'));
     flash()->success('Twoje zapytanie zostało wysłane poprawnie, oczekuj odpowiedzi na swojej skrzynce pocztowej. Zazwyczaj trwa to do 24h, pozdrawiamy, ekipa PLERP!');
     return redirect('/');
 }
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     $faker = Faker\Factory::create();
     for ($i = 0; $i < 100; $i++) {
         $question = \App\Question::create(['question' => $faker->text(300), 'option_1' => $faker->text(100), 'option_2' => $faker->text(100), 'option_3' => $faker->text(100), 'option_4' => $faker->text(100), 'answer' => $faker->numberBetween(1, 4), 'user_create' => $faker->numberBetween(1, 10)]);
     }
 }
 public function store()
 {
     $input = Request::all();
     $article = Question::create($input);
     $article->user_id = Auth::user()->id;
     $article->save();
     return redirect('questions');
 }
 /**
  * Run the question seeds.
  *
  * @return void
  */
 public function run()
 {
     $faker = Faker::create();
     $users = User::all()->lists('id')->all();
     foreach (range(1, 20) as $index) {
         Question::create(['user_id' => $faker->randomElement($users), 'title' => $faker->sentence(10), 'body' => $faker->paragraph(5)]);
     }
 }
 public function run()
 {
     $faker = Faker\factory::create();
     DB::table('questions')->delete();
     foreach (range(1, 5) as $index) {
         Question::create(['question' => $faker->word, 'points' => $faker->numberBetween($min = 1, $max = 100), 'type' => $faker->numberBetween($min = 1, $max = 2)]);
     }
 }
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     $faker = Faker\Factory::create('zh_TW');
     Question::truncate();
     //
     foreach (range(1, 1000) as $number) {
         Question::create(['stages_id' => $faker->randomElement($array = array('101', '102', '103', '104', '105', '106', '107', '108', '109', '110', '201', '202', '203', '204', '205', '206', '207', '301', '302', '303', '304', '305', '401', '501', '601')), 'qtitle' => $number . $faker->text, 'ans1_title' => 'ans' . $number, 'ans2_title' => 'ans' . $number, 'ans3_title' => 'ans' . $number, 'ans4_title' => 'ans' . $number, 'ans5_title' => 'ans' . $number, 'ans6_title' => '放棄', 'answer' => rand(1, 5), 'detailed' => $faker->text, 'created_at' => Carbon\Carbon::now(), 'updated_at' => Carbon\Carbon::now()]);
     }
 }
 /**
  * Store a newly created resource in storage.
  *
  * @return Response
  */
 public function store(Request $request)
 {
     $this->validate($request, ['title' => 'required', 'description' => 'required']);
     //
     $input = $request->all();
     Question::create($input);
     Session::flash('flash_message', 'Question successfully added!');
     return redirect()->back();
 }
 /**
  * Store a newly created resource in storage.
  *
  * @return Response
  */
 public function storeQuestion()
 {
     $input = Request::all();
     $user = \Auth::user();
     $input['published_at'] = Carbon::now();
     $fiche_id = Session::get('fiche_id');
     $question = \App\Question::create($input);
     return view('back.newQuestion', compact('question', 'fiche_id', 'user'));
 }
Exemple #13
0
 protected static function saveAllQuestions($questions, $test)
 {
     foreach ($questions as $question) {
         $savedQuestion = Question::create(['test_id' => $test->id, 'title' => $question['title']]);
         foreach ($question['options'] as $i => $option) {
             Option::create(['question_id' => $savedQuestion->id, 'value' => $option]);
         }
     }
 }
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     DB::table('questions')->delete();
     $questions = array(['question' => 'question1?', 'user_id' => 3], ['question' => 'question2?', 'user_id' => 2], ['question' => 'question3?', 'user_id' => 4], ['question' => 'question4?', 'user_id' => 1]);
     // Loop through each user above and create the record for them in the database
     foreach ($questions as $question) {
         Question::create($question);
     }
 }
Exemple #15
0
 public function saveNewTest($test)
 {
     $newTest = Test::create(['name' => $test['name'], 'preparation' => $test['preparation'], 'time' => $test['time']]);
     // Nested loop to add questions > options
     foreach ($test['questions'] as $question) {
         $savedQuestion = Question::create(['test_id' => $newTest->id, 'title' => $question['title'], 'correct' => $question['correct']]);
         foreach ($question['options'] as $i => $option) {
             Option::create(['question_id' => $savedQuestion->id, 'value' => $option]);
         }
     }
 }
Exemple #16
0
 public function addQuestion(Request $request)
 {
     $question['title'] = $this->mysql_real_escape_string($request->input('title'));
     $question['sectionId'] = $request->input('sectionId');
     try {
         $result = Question::create($question);
     } catch (\Exception $e) {
         return response()->json(['error' => ['message' => 'Could not save question' . $e->getMessage(), 'code' => 101]]);
     }
     return response()->json(['question' => $result]);
 }
 public function store(QuestionRequest $request)
 {
     foreach ($request->choices as $choice) {
         $choiceModels[] = new Choice(['choice_text' => $choice]);
     }
     $data = $request->all();
     $data["user_id"] = \Auth::user()->id;
     $question = Question::create($data);
     $question->choices()->saveMany($choiceModels);
     session()->flash('flash_msg', 'You have successfully edited a poll.');
     return redirect('/');
 }
Exemple #18
0
 public function saveFromNested($test)
 {
     // Clear already existing questions for this particular test.
     Question::where('test_id', $test['id'])->delete();
     foreach ($test['questions'] as $question) {
         $savedQuestion = Question::create(['test_id' => $test['id'], 'title' => $question['title'], 'correct' => $question['correct']]);
         // Clear already existing options for this particular question.
         Option::where('question_id', $savedQuestion['id'])->delete();
         foreach ($question['options'] as $i => $option) {
             Option::create(['question_id' => $savedQuestion->id, 'value' => $option]);
         }
     }
 }
Exemple #19
0
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     Model::unguard();
     Question::create(['step' => 1, 'name' => 'name', 'type' => 'text', 'text' => 'What is your name?', 'rule' => 'required|min:2|max:50']);
     Question::create(['step' => 2, 'name' => 'color', 'type' => 'text', 'text' => 'What is your favorite color?', 'rule' => 'required|min:3']);
     Question::create(['step' => 3, 'name' => 'pet', 'type' => 'radio', 'text' => 'Which type of pet is best?', 'values' => ['Cats', 'Dogs', 'Lizards'], 'rule' => 'required|in:Cats,Dogs']);
     Question::create(['step' => 1, 'name' => 'nickname', 'type' => 'text', 'text' => 'What is your nickname? (optional)', 'rule' => 'sometimes|min:2|max:50']);
     Question::create(['step' => 2, 'name' => 'shape', 'type' => 'text', 'text' => 'What is your favorite shape?', 'rule' => 'required']);
     Question::create(['step' => 3, 'name' => 'pet_count', 'type' => 'text', 'text' => 'How many pets do you have?', 'rule' => 'integer']);
     Question::create(['step' => 4, 'name' => 'opt_in', 'type' => 'radio', 'text' => 'Can we send you email?', 'values' => ['Yes', 'No'], 'rule' => 'required|in:Yes,No']);
     Question::create(['step' => 4, 'name' => 'how_hear', 'type' => 'text', 'text' => 'How did you hear about us? (optional)']);
     Model::reguard();
 }
 /**
  * Store a newly created resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @return \Illuminate\Http\Response
  */
 public function store(Request $request)
 {
     //authenticate and get user id
     $user = JWTAuth::parseToken()->authenticate();
     $user_id = $user->id;
     //validate data
     $validator = Validator::make($request->all(), array('question' => 'required|max:255'));
     if ($validator->fails()) {
         return $validator->errors()->all();
     } else {
         Question::create(['question' => $request['question'], 'user_id' => $user_id, 'is_published' => true]);
         return response()->json(['success' => true, 'message' => "Question Added Successfully", 'question' => $request['question']]);
     }
 }
 public function addQuestion(Request $request)
 {
     $validator = \Validator::make($request->all(), ['question' => 'required', 'answer' => 'required']);
     if ($validator->passes()) {
         $question = Question::where('question_id', $request->input('question'))->where('answer', $request->input('answer'))->first();
         if ($question) {
             $question->increment('agreements');
         } else {
             Question::create(['question_id' => $request->input('question'), 'answer' => $request->input('answer')]);
         }
         return response("OK", 200);
     }
     return response("Bad", 400);
 }
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     $faker = Factory::create('fr_FR');
     $subjectsCount = Subject::all()->count();
     for ($qcms = 0; $qcms < 100; $qcms++) {
         $qcm = Qcm::create(['user_id' => 1, 'subject_id' => rand(1, $subjectsCount - 1), 'name' => $faker->sentence(6), 'description' => $faker->sentence(40)]);
         for ($questions = 0; $questions < rand(5, 10); $questions++) {
             $question = Question::create(['qcm_id' => $qcm->id, 'question' => $faker->sentence(20)]);
             for ($answers = 0; $answers < rand(2, 4); $answers++) {
                 Answer::create(['question_id' => $question->id, 'answer' => $faker->sentence(10), 'isValid' => $answers == 0]);
             }
         }
     }
 }
 /**
  * @param Request $request
  * @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
  */
 public function store(QuestionFormRequest $request)
 {
     //question, answerType, event_id
     $input['event_id'] = $request->input('event');
     $input['question'] = $request->input('question');
     $input['answerType'] = $request->input('answerType');
     $input['listItems'] = $request->input('listItems');
     // put the formatted dropdownlist into $input['listItems']
     Question::create($input);
     //Flash a message to the user
     \Flash::success('Question added successfully');
     //Redirect back to the admin page
     //return redirect(action('EventsController@admin', $request->input('event')));
     return Redirect::back()->with(['tabName' => 'questions']);
 }
 /**
  * Store a newly created resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @return \Illuminate\Http\Response
  */
 public function store(QuestionRequest $request)
 {
     $qanda = json_decode(stripslashes($request["questions_and_answers"]));
     $course_id = $request["course_id"];
     $questions = Question::where('course_id', '=', $course_id)->get();
     if (count($questions)) {
         Flash::error('Question(s) have already been set.');
         return redirect()->route('question.create');
     }
     for ($i = 0; $i < count($qanda); $i++) {
         Question::create(['course_id' => $course_id, 'question' => $qanda[$i]->Question, 'answers' => $qanda[$i]->Answers]);
     }
     Flash::success('The Question(s) have been set.');
     return redirect()->route('question.index');
 }
 public function create(Request $request)
 {
     if ($request->isMethod('get')) {
         $this->data['roles'] = $this->getRoles();
         $this->data['types'] = $this->getTypes();
         $this->data['items'] = Question::where('enabled', 1)->get();
         return view('pages.question.create', $this->data);
     } elseif ($request->isMethod('post')) {
         $data = $request->all();
         if (!isset($data['helptext'])) {
             $data['helptext'] = null;
         }
         Question::create($data);
         return redirect('question');
     }
 }
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     $faker = Faker::create();
     for ($i = 0; $i < 100; $i++) {
         Question::create(['skill_id' => $faker->numberBetween(1, 53), 'difficulty_id' => $faker->numberBetween(1, 3), 'question' => $faker->sentence(2), 'question_image' => $faker->imageUrl(500, 300, 'cats'), 'answer1' => '35', 'answer1_image' => $faker->imageUrl(250, 150, 'food'), 'answer2' => '-5', 'answer2_image' => $faker->imageUrl(250, 150, 'food'), 'answer3' => '15', 'answer3_image' => $faker->imageUrl(250, 150, 'people'), 'answer0' => '25', 'answer0_image' => $faker->imageUrl(250, 150, 'nature'), 'user_id' => $faker->numberBetween(1, 15), 'correct_answer' => 2]);
     }
     Question::create(['skill_id' => 2, 'difficulty_id' => 1, 'question' => 'x + 10 = 5. What is x?', 'question_image' => $faker->imageUrl(500, 300, 'cats'), 'answer1' => '35', 'answer1_image' => $faker->imageUrl(250, 150, 'food'), 'answer2' => '-5', 'answer2_image' => $faker->imageUrl(250, 150, 'food'), 'answer3' => '15', 'answer3_image' => $faker->imageUrl(250, 150, 'people'), 'answer0' => '25', 'answer0_image' => $faker->imageUrl(250, 150, 'nature'), 'user_id' => 1, 'correct_answer' => 2]);
     Question::create(['skill_id' => 2, 'difficulty_id' => 2, 'question' => 'y + 10 = 5. What is y?', 'question_image' => $faker->imageUrl(500, 300, 'cats'), 'answer1' => '35', 'answer1_image' => $faker->imageUrl(250, 150, 'food'), 'answer2' => '5', 'answer2_image' => $faker->imageUrl(250, 150, 'food'), 'answer3' => '-5', 'answer3_image' => $faker->imageUrl(250, 150, 'people'), 'answer0' => '25', 'answer0_image' => $faker->imageUrl(250, 150, 'nature'), 'user_id' => 2, 'correct_answer' => 3]);
     Question::create(['skill_id' => 3, 'difficulty_id' => 3, 'question' => 'z + 10 = 5. What is z?', 'question_image' => $faker->imageUrl(500, 300, 'cats'), 'answer1' => '35', 'answer1_image' => $faker->imageUrl(250, 150, 'food'), 'answer2' => '5', 'answer2_image' => $faker->imageUrl(250, 150, 'food'), 'answer3' => '15', 'answer3_image' => $faker->imageUrl(250, 150, 'people'), 'answer0' => '-5', 'answer0_image' => $faker->imageUrl(250, 150, 'nature'), 'user_id' => 1, 'correct_answer' => 0]);
     Question::create(['difficulty_id' => 1, 'question' => 'The base and height of a triangle is 9cm and 4 cm respectively. What is the area?', 'question_image' => $faker->imageUrl(400, 300, 'cats'), 'answer1' => '38', 'answer1_image' => $faker->imageUrl(250, 150, 'food'), 'answer2' => '18', 'answer2_image' => $faker->imageUrl(250, 150, 'food'), 'answer3' => '15', 'answer3_image' => $faker->imageUrl(250, 150, 'people'), 'answer0' => '20', 'answer0_image' => $faker->imageUrl(250, 150, 'nature'), 'user_id' => 2, 'correct_answer' => 2]);
     Question::create(['difficulty_id' => 2, 'question' => 'The base and height of a triangle is 9cm and 8 cm respectively. What is the area?', 'question_image' => $faker->imageUrl(400, 300, 'cats'), 'answer1' => '36', 'answer1_image' => $faker->imageUrl(250, 150, 'food'), 'answer2' => '18', 'answer2_image' => $faker->imageUrl(250, 150, 'food'), 'answer3' => '15', 'answer3_image' => $faker->imageUrl(250, 150, 'people'), 'answer0' => '20', 'answer0_image' => $faker->imageUrl(250, 150, 'nature'), 'user_id' => 1, 'correct_answer' => 1]);
     Question::create(['skill_id' => 3, 'difficulty_id' => 3, 'question' => 'The base and height of a triangle is 14 cm and 4 cm respectively. What is the area?', 'question_image' => $faker->imageUrl(500, 300, 'cats'), 'answer1' => '38', 'answer1_image' => $faker->imageUrl(250, 150, 'food'), 'answer2' => '18', 'answer2_image' => $faker->imageUrl(250, 150, 'food'), 'answer3' => '15', 'answer3_image' => $faker->imageUrl(250, 150, 'people'), 'answer0' => '28', 'answer0_image' => $faker->imageUrl(250, 150, 'nature'), 'user_id' => 1, 'correct_answer' => 0]);
     Question::create(['skill_id' => 1, 'difficulty_id' => 1, 'question' => 'How many meters is 2 km?', 'question_image' => $faker->imageUrl(500, 300, 'cats'), 'answer1' => '2400 m', 'answer1_image' => $faker->imageUrl(250, 150, 'food'), 'answer2' => '2000 m', 'answer2_image' => $faker->imageUrl(250, 150, 'food'), 'answer3' => '2500 m', 'answer3_image' => $faker->imageUrl(250, 150, 'people'), 'answer0' => '2 m', 'answer0_image' => $faker->imageUrl(250, 150, 'nature'), 'user_id' => 1, 'correct_answer' => 2]);
     Question::create(['skill_id' => 2, 'difficulty_id' => 2, 'question' => 'How many meters is 4 km?', 'question_image' => $faker->imageUrl(500, 300, 'cats'), 'answer1' => '2400 m', 'answer1_image' => $faker->imageUrl(250, 150, 'food'), 'answer2' => '2000 m', 'answer2_image' => $faker->imageUrl(250, 150, 'food'), 'answer3' => '4000 m', 'answer3_image' => $faker->imageUrl(250, 150, 'people'), 'answer0' => '2 m', 'answer0_image' => $faker->imageUrl(250, 150, 'nature'), 'user_id' => 1, 'correct_answer' => 3]);
     Question::create(['skill_id' => 1, 'difficulty_id' => 3, 'question' => 'How many meters is 200 km?', 'question_image' => $faker->imageUrl(500, 300, 'cats'), 'answer0' => '2000 m', 'answer0_image' => $faker->imageUrl(250, 150, 'nature'), 'answer1' => '24000 m', 'answer1_image' => $faker->imageUrl(500, 300, 'food'), 'answer2' => '200000 m', 'answer2_image' => $faker->imageUrl(250, 150, 'food'), 'answer3' => '25000 m', 'answer3_image' => $faker->imageUrl(250, 150, 'people'), 'user_id' => 2, 'correct_answer' => 2]);
     Question::create(['skill_id' => 8, 'difficulty_id' => 3, 'question' => 'How many meters is 200 km?', 'question_image' => $faker->imageUrl(500, 300, 'cats'), 'answer0' => '2000 m', 'answer0_image' => $faker->imageUrl(250, 150, 'nature'), 'answer1' => '24000 m', 'answer1_image' => $faker->imageUrl(500, 300, 'food'), 'answer2' => '200000 m', 'answer2_image' => $faker->imageUrl(250, 150, 'food'), 'answer3' => '25000 m', 'answer3_image' => $faker->imageUrl(250, 150, 'people'), 'user_id' => 2, 'correct_answer' => 2]);
 }
Exemple #27
0
 /**
  * Store a newly created resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @return \Illuminate\Http\Response
  */
 public function store(Request $request)
 {
     $rules = ['name' => 'required|min:5', 'class' => 'required', 'subject_id' => 'required', 'partition_id' => 'required'];
     $attrName = [0 => 'с първият отговор', 1 => 'с вторият отговор', 2 => 'с третият отговор', 3 => 'с четвъртият отговор', 4 => 'с петият отговор', 5 => 'с шестият отговор', 6 => 'с седмият отговор', 7 => 'с осмият отговор'];
     foreach ($request->get('answers') as $key => $value) {
         $rules['answers.' . $key] = 'required|min:5';
         $messages['answers.' . $key . '.required'] = 'Полето ' . $attrName[$key] . ' е задължително.';
         $messages['answers.' . $key . '.min'] = 'Полето ' . $attrName[$key] . ' трябва да бъде минимум :min знака.';
     }
     $validator = \Validator::make($request->all(), $rules, $messages);
     if ($validator->fails()) {
         return $validator->errors()->toJSON();
     }
     $user_id = \Auth::user()->id;
     $input = $request->all();
     $input['user_id'] = $user_id;
     $reqCorrect = $request->get('correct');
     if (sizeof($reqCorrect) > 1) {
         $input['type'] = 'multiple';
     } else {
         $input['type'] = 'one';
     }
     $question = Question::create($input);
     foreach ($request->get('answers') as $key => $value) {
         $correct = false;
         if (sizeof($reqCorrect) > 1) {
             foreach ($reqCorrect as $k => $v) {
                 if ($key == $reqCorrect[$k]) {
                     $correct = true;
                 }
             }
         } else {
             if ($key == $reqCorrect[0]) {
                 $correct = true;
             }
         }
         Answer::create(['name' => $value, 'question_id' => $question->id, 'correct' => $correct]);
     }
     \Session::flash('flash_message', 'Въпросът беше успешно добавен!');
     return ['type' => 'redirect', 'url' => url(route('admin.question.index'))];
 }
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     Model::unguard();
     // $this->call(UserTableSeeder::class);
     // $this->call(ClassTableSeeder::class);
     //Optional just to clear table
     // DB::table('answers')->delete();
     // DB::table('questions')->delete();
     // DB::table('classes')->delete();
     // DB::table('users')->delete();
     $student1 = User::create(['name' => 'Scotty Gomez', 'email' => str_random(2) . '@gmail.com', 'password' => bcrypt('secret'), 'type' => 'student']);
     $student2 = User::create(['name' => 'Misha Dowd', 'email' => str_random(2) . '@gmail.com', 'password' => bcrypt('secret'), 'type' => 'student']);
     $lecturer = User::create(['name' => 'Dr. Andre Chen', 'email' => str_random(2) . '@gmail.com', 'password' => bcrypt('secret'), 'type' => 'lecturer']);
     $this->command->info('User Created!');
     $course = Course::create(['name' => 'Math', 'term' => 'Fall2020', 'lecturer_id' => $lecturer->id]);
     $this->command->info('Course Created!');
     $quiz = Quiz::create(['course_id' => $course->id, 'description' => 'A Quiz to Test Your Might!', 'quizTime' => '20', 'startDate' => '10.29.2015', 'endDate' => '10.30.2015']);
     $this->command->info('Quiz Created!');
     //Questions
     $q = Question::create(['prompt' => 'What is the sqare root of 4?', 'difficulty' => 'easy']);
     $q1 = Question::create(['prompt' => 'What is 2 X 3?', 'difficulty' => 'easy']);
     $this->command->info('2 Questions Created!');
     //Answers
     $a = Answer::create(['text' => '6', 'image' => NULL]);
     $a1 = Answer::create(['text' => '2', 'image' => NULL]);
     $a2 = Answer::create(['text' => '6', 'image' => NULL]);
     $a11 = Answer::create(['text' => '5', 'image' => NULL]);
     $this->command->info('All 4 Answers Created!');
     // Adding User to Course
     $course->users()->sync([$student1->id, $student2->id]);
     // Syncing Quiz to Questions
     $quiz->questions()->sync([$q->id, $q1->id]);
     // Syncing (Binding Qustion to Answer)
     $q->answers()->sync([$a->id, $a1->id]);
     $q1->answers()->sync([$a2->id, $a11->id]);
     $this->command->info('Everything Created and Linked!');
     Model::reguard();
 }
Exemple #29
0
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     DB::table('employees')->delete();
     $faker = \Faker\Factory::create();
     /**
      * this for admin account
      */
     $emp = Employee::create(['user_id' => 801, 'name' => 'Robinson L. Legaspi', 'department' => 'quality_assurance', 'station' => 'DCC', 'position' => 'Management System Officer', 'email' => '*****@*****.**', 'status' => 'active']);
     User::create(['employee_id' => 801, 'access_level' => 'admin', 'password' => 'admin', 'avatar' => 'default.png']);
     Question::create(['user_id' => $emp->user_id, 'question' => 'What are you?', 'answer' => 'user']);
     /**
      * this for process account
      */
     $emp = Employee::create(['user_id' => 802, 'name' => 'Nepthal Dave S. Pakingan', 'department' => 'process_engineering', 'station' => 'Process Engineer', 'position' => 'HR Programmer', 'email' => '*****@*****.**', 'status' => 'active']);
     User::create(['employee_id' => 802, 'access_level' => 'signatory', 'password' => 'user', 'avatar' => 'default.png']);
     Question::create(['user_id' => $emp->user_id, 'question' => 'What are you?', 'answer' => 'user']);
     /**
      * this for process account
      */
     $emp = Employee::create(['user_id' => 4550, 'name' => 'Pauleen Moya', 'department' => 'production', 'station' => 'PL1', 'position' => 'Supervisor', 'email' => '*****@*****.**', 'status' => 'active']);
     User::create(['employee_id' => 4550, 'access_level' => 'signatory', 'password' => 'user', 'avatar' => 'default.png']);
     Question::create(['user_id' => $emp->user_id, 'question' => 'What are you?', 'answer' => 'user']);
     /**
      * this for dummy account
      */
     foreach (range(1, 200) as $index) {
         $department = $faker->randomElement(['production', 'process_engineering', 'quality_assurance', 'other_department']);
         $station['quality_assurance'] = ['quality assurance'];
         $station['process_engineering'] = ['process engineering'];
         $station['production'] = ['pl1', 'pl2', 'pl3', 'pl4', 'pl7', 'pl9'];
         $station['other_department'] = ['equipment engineering', 'facilities', 'mis', 'human resource', 'purchasing and logistics', 'finance', 'utilities'];
         $emp = Employee::create(['user_id' => $faker->unique()->randomNumber, 'name' => $faker->name('male' | 'female'), 'department' => $department, 'station' => $faker->randomElement($station[$department]), 'position' => $faker->randomElement(['Supervisor', 'Operator', 'Manager']), 'status' => $faker->randomElement(['active', 'resigned']), 'email' => $faker->email]);
         User::create(['employee_id' => $emp->user_id, 'access_level' => $faker->randomElement(['user', 'signatory']), 'password' => '8d', 'avatar' => 'default.png']);
         Question::create(['user_id' => $emp->user_id, 'question' => 'What are you?', 'answer' => 'user']);
     }
 }
 /**
  * Add the questions by user.
  *
  * @return Response
  */
 public function add(Request $request)
 {
     try {
         if ($request->input('question') != '') {
             $validator = Validator::make($request->all(), ['question' => 'required|max:250']);
             if ($validator->fails()) {
                 return redirect()->back()->withInput()->withErrors($validator->errors());
             } else {
                 $data = array("question" => $request->input('question'), "user_id" => Auth::user()->id);
                 $questionAdd = Question::create($data);
                 if ($questionAdd) {
                     return redirect('/questions')->with('success', 'Question created successfully.');
                 } else {
                     return redirect()->back()->withInput()->withErrors("Cannot add now,plese try after some time");
                 }
             }
         } else {
             return view('question.add');
         }
     } catch (Exception $e) {
         return redirect()->back()->withInput()->withErrors($e->getMessage());
     }
     //return view('home');
 }