本文整理汇总了PHP中app\Question类的典型用法代码示例。如果您正苦于以下问题:PHP Question类的具体用法?PHP Question怎么用?PHP Question使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Question类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: store
public function store(QuestionFormRequest $request)
{
//return $request->all();
$slug = uniqid();
$question = new Question(array('question' => $request->get('question'), 'option1' => $request->get('option1'), 'option2' => $request->get('option2'), 'option3' => $request->get('option3'), 'option4' => $request->get('option4'), 'slug' => $slug));
$question->save();
return redirect('create')->with('status', 'Your question has been saved! Its unique id is: ' . $slug);
}
示例2: destroy
/**
* Remove the specified resource from storage.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function destroy(Question $question)
{
$delete = $question->delete();
if ($delete) {
return 0;
} else {
return 1;
}
}
示例3: postCreateAQuestion
public function postCreateAQuestion(Request $request)
{
$question = new Question();
$question->user_id = \Auth::user()->id;
$question->title = $request->title;
$question->slug = str_slug($request->title, "-");
$question->save();
return redirect('/questions');
}
示例4: syncTags
/**
* Sync up the list of tags in the database.
*
* @param Article $article
* @param array $tags
*/
private function syncTags(Question $question, array $tags)
{
// Create new tags if needed and get ids
$tagIds = [];
foreach ($tags as $tag) {
$tagId = Tag::firstOrCreate(['name' => mb_strtolower($tag, 'UTF-8')])->id;
$tagIds[] = $tagId;
}
// Sync tags based on ids
$question->tags()->sync($tagIds);
}
示例5: addTraining
public function addTraining(Request $request)
{
$data = array('name' => htmlentities($request->input('title')), 'description' => htmlentities($request->input('description')), 'image' => $request->input('imagine'), 'areaType' => substr($request->input('arie'), 0, 1), 'area' => htmlentities(substr($request->input('arie'), 1)), 'locuri' => htmlentities($request->input('locuri')), 'ziua' => htmlentities($request->input('ziua')), 'ora' => htmlentities($request->input('ora')));
$data['intrebari'] = array();
$idIntrebare = 1;
$intrebare = htmlentities($request->input('intrebare' . $idIntrebare));
while (isset($intrebare)) {
array_push($data['intrebari'], $intrebare);
$idIntrebare++;
$intrebare = $request->input('intrebare' . $idIntrebare);
}
$rules = array('name' => 'required', 'description' => 'required', 'image' => 'image', 'area' => 'exists:areas,id', 'subarea' => 'exists:subareas,id', 'locuri' => 'numeric|required', 'ziua' => 'required', 'ora' => 'required');
if ($data['areaType'] == 's') {
$data['subarea'] = $data['area'];
$data['area'] = Subarea::where('id', $data['subarea'])->first()->area_id;
} else {
$data['subarea'] = "";
}
$validator = Validator::make($data, $rules);
if (!$validator->fails()) {
$training = new Training();
$nameOfImage = $this->generateRandomString() . '.jpg';
Storage::put('images/' . $nameOfImage, $data['image']);
$training->trainer_id = Auth::user()->id;
$training->name = $data['name'];
$training->description = $data['description'];
$training->image = "images/" . $nameOfImage;
$training->area_id = $data['area'];
$training->subarea_id = $data['subarea'];
$training->locuri = $data['locuri'];
$training->save();
$group = new Group();
$group->trainer_id = Auth::user()->id;
$group->training_id = $training->id;
$group->area_id = $training->area_id;
$group->subarea_id = $training->subarea_id;
$group->groupOrder = 1;
$group->data = $data['ziua'];
$group->ora = $data['ora'];
$group->save();
foreach ($data['intrebari'] as $intrebare) {
$question = new Question();
$question->training_id = $training->id;
$question->question = $intrebare;
$question->posted_by = Auth::user()->id;
$question->required = 1;
$question->save();
}
return redirect('/trainer');
} else {
return $data['areaType'];
}
}
示例6: testShowQuestion
public function testShowQuestion()
{
$survey = new Survey(['title' => 'Testing survey']);
$question = new Question(['body' => 'What is this?', 'kind' => 'voice']);
$survey->save();
$question->survey()->associate($survey)->save();
$response = $this->call('GET', route('question.show', ['id' => $question->id]));
$savingUrl = route('question.question_response.store', ['question_id' => $question->id], false);
$absoluteSavingUrl = route('question.question_response.store', ['question_id' => $question->id]);
$this->assertContains($question->body, $response->getContent());
$this->assertContains($savingUrl . '?Kind=voice', $response->getContent());
$this->assertNotContains($absoluteSavingUrl, $response->getContent());
}
示例7: store
public function store(Request $request, $idTraj)
{
$question = new Question();
$libQuest = $request->question;
$question->libQuest = $libQuest;
$question->trajet()->associate(Trajet::find($idTraj));
$question->save();
$trajet = Trajet::find($question->idTraj);
$data = array("question" => $question->libQuest, "idTraj" => $question->idTraj, "mailCond" => $trajet->user->email, "nomCond" => $trajet->user->prenomMemb);
Mail::send('recherche.question.email', $data, function ($message) use($trajet, $question) {
$message->to($trajet->user->email, $trajet->user->prenomMemb)->subject('Vous avez reçu une question !');
});
return redirect()->route('detailRecherche', $idTraj);
}
示例8: run
/**
* Run the database seeds.
*
* @return void
*/
public function run()
{
$json = Storage::get('questions.json');
$this->command->info($json);
$questions = json_decode($json, true);
foreach ($questions['questions'] as $question_keys => $question) {
$this->command->info("Adding Question: " . $question_keys . "...");
if ($question["type"] != "true-false") {
$answers = $question['answers'];
unset($question['answers']);
}
$q = new Question($question);
$q->save();
foreach ($question as $question_attribute_name => $question_attribute_value) {
$this->command->info($question_attribute_name);
}
if ($q->type == "true-false") {
$this->command->info("Adding True/False Question...");
$answer = $question['answer'];
$aFalse;
$aTrue;
if (Answer::where('text', 'true')->count() >= 1) {
$aTrue = Answer::where('text', 'true')->first();
} else {
$aTrue = new Answer(['text' => 'true']);
$aTrue->save();
}
if (Answer::where('text', 'false')->count() >= 1) {
$aFalse = Answer::where('text', 'false')->first();
} else {
$aFalse = new Answer(['text' => 'false']);
$aFalse->save();
}
$q->answers()->save($aFalse, ['is_correct' => $answer ? 0 : 1]);
$q->answers()->save($aTrue, ['is_correct' => $answer ? 1 : 0]);
} else {
$this->command->info("Adding answers...");
$answer_ids = array();
foreach ($answers as $answer_index => $answer) {
$this->command->info("Adding " . ($answer_index + 1) . "...");
$a = new Answer($answer);
$a->save();
$q->answers()->save($a, ['is_correct' => $answer['is_correct'] === "false" ? 0 : 1]);
}
}
$this->command->info("");
}
}
示例9: run
/**
* Run the database seeds.
*
* @return void
*/
public function run()
{
DB::statement('SET FOREIGN_KEY_CHECKS=0;');
DB::table('questions')->truncate();
$quiz = new Question();
$quiz->quiz_id = 1;
$quiz->user_id = 1;
$quiz->title = 'Seeded question 1';
$quiz->save();
$quiz = new Question();
$quiz->quiz_id = 1;
$quiz->user_id = 1;
$quiz->title = 'Seeded question 2';
$quiz->save();
DB::statement('SET FOREIGN_KEY_CHECKS=1;');
}
示例10: add
public function add(Request $request, $code)
{
$j = 0;
$answer = '';
$answer_corrected = '';
for ($i = 1; $i <= count($request->input('variants')); $i++) {
if ($j < count($request->input('answers'))) {
if ($request->input('answers')[$j] == $i) {
$answer = $answer . ';' . "1";
$j++;
} else {
$answer = $answer . ';' . "0";
}
} else {
$answer = $answer . ';' . "0";
}
}
$answer[0] = '';
echo strlen($answer);
for ($i = 1; $i < strlen($answer); $i++) {
$answer_corrected = $answer_corrected . $answer[$i];
}
echo strlen($answer_corrected);
$title = $request->input('variants')[0];
for ($i = 1; $i < count($request->input('variants')); $i++) {
$title = $title . ';' . $request->input('variants')[$i];
}
Question::insert(array('code' => $code, 'title' => $title, 'variants' => '', 'answer' => $answer_corrected, 'points' => $request->input('points')));
}
示例11: 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('/');
}
示例12: questions
function questions()
{
$faker = Faker::create();
foreach (range(0, 10) as $i) {
Question::create(['body' => $faker->paragraph]);
}
}
示例13: index
public function index()
{
$questions = Question::all();
$tpl['user'] = \Auth::user();
$tpl['questions'] = $questions;
return view('home', $tpl);
}
示例14: 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)]);
}
}
示例15: testStoreResponse
public function testStoreResponse()
{
$survey = new Survey(['title' => 'Testing survey']);
$questionOne = new Question(['body' => 'What is this?', 'kind' => 'voice']);
$questionTwo = new Question(['body' => 'What is that?', 'kind' => 'voice']);
$survey->save();
$questionOne->survey()->associate($survey)->save();
$questionTwo->survey()->associate($survey)->save();
$responseForQuestion = ['RecordingUrl' => '//somefake.mp3', 'CallSid' => '7h1515un1qu3', 'Kind' => 'voice'];
$firstResponse = $this->call('POST', route('question.question_response.store', ['question_id' => $questionOne->id]), $responseForQuestion);
$routeToNextQuestion = route('question.show', ['id' => $questionTwo->id], false);
$routeToNextQuestionAbsolute = route('question.show', ['id' => $questionTwo->id], true);
$this->assertContains($routeToNextQuestion, $firstResponse->getContent());
$secondResponse = $this->call('POST', route('question.question_response.store', ['question_id' => $questionTwo->id]), $responseForQuestion);
$this->assertNotContains('Redirect', $secondResponse->getContent());
}