本文整理汇总了PHP中app\Question::create方法的典型用法代码示例。如果您正苦于以下问题:PHP Question::create方法的具体用法?PHP Question::create怎么用?PHP Question::create使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类app\Question
的用法示例。
在下文中一共展示了Question::create方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: questions
function questions()
{
$faker = Faker::create();
foreach (range(0, 10) as $i) {
Question::create(['body' => $faker->paragraph]);
}
}
示例2: store
/**
* 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');
}
示例3: store
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');
}
示例4: post_write
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}");
}
示例5: store
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('/');
}
示例6: run
/**
* 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)]);
}
}
示例7: store
public function store()
{
$input = Request::all();
$article = Question::create($input);
$article->user_id = Auth::user()->id;
$article->save();
return redirect('questions');
}
示例8: run
/**
* 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)]);
}
}
示例9: run
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)]);
}
}
示例10: run
/**
* 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()]);
}
}
示例11: store
/**
* 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();
}
示例12: storeQuestion
/**
* 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'));
}
示例13: saveAllQuestions
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]);
}
}
}
示例14: run
/**
* 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);
}
}
示例15: saveNewTest
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]);
}
}
}