diff --git a/app/Http/Controllers/QuestionController.php b/app/Http/Controllers/QuestionController.php index e85d6c7..c1fa36f 100644 --- a/app/Http/Controllers/QuestionController.php +++ b/app/Http/Controllers/QuestionController.php @@ -2,7 +2,7 @@ namespace App\Http\Controllers; -use App\Question; +use App\Models\Question; use Illuminate\Http\Request; class QuestionController extends Controller @@ -24,7 +24,7 @@ public function __construct() */ public function index() { - return view('questions.index'); + return view('questions.index', ['questions' => Question::all()]); } /** @@ -45,13 +45,20 @@ public function create() */ public function store(Request $request) { - // + $question = new Question; + $question->title = $request['title']; + $question->description = $request['description']; + $question->maxCheck = $request['maxCheck'] ?? 1; + $question->save(); + $question->options()->createMany($request['options']); + + return $question; } /** * Display the specified resource. * - * @param \App\Question $question + * @param \App\Models\Question $question * @return \Illuminate\Http\Response */ public function show(Question $question) @@ -62,7 +69,7 @@ public function show(Question $question) /** * Show the form for editing the specified resource. * - * @param \App\Question $question + * @param \App\Models\Question $question * @return \Illuminate\Http\Response */ public function edit(Question $question) @@ -74,22 +81,27 @@ public function edit(Question $question) * Update the specified resource in storage. * * @param \Illuminate\Http\Request $request - * @param \App\Question $question + * @param \App\Models\Question $question * @return \Illuminate\Http\Response */ public function update(Request $request, Question $question) { - // + $question->title = $request->question['title']; + $question->description = $request->question['description']; + $question->maxCheck = $request->question['maxCheck'] ?? 1; + $question->save(); + + return $question; } /** * Remove the specified resource from storage. * - * @param \App\Question $question + * @param \App\Models\Question $question * @return \Illuminate\Http\Response */ public function destroy(Question $question) { - // + $question->delete(); } } diff --git a/app/Models/Question.php b/app/Models/Question.php index 67cb3b9..79688fc 100644 --- a/app/Models/Question.php +++ b/app/Models/Question.php @@ -6,7 +6,7 @@ class Question extends Model { - protected $fillable = [ 'title', 'description', ]; + protected $fillable = [ 'title', ]; /** * A poll has many options related to diff --git a/database/migrations/2019_07_22_035029_create_questions_table.php b/database/migrations/2019_07_22_035029_create_questions_table.php index a3e7111..3eb9e80 100644 --- a/database/migrations/2019_07_22_035029_create_questions_table.php +++ b/database/migrations/2019_07_22_035029_create_questions_table.php @@ -16,7 +16,7 @@ public function up() Schema::create('questions', function (Blueprint $table) { $table->bigIncrements('id'); $table->string('title'); - $table->string('description'); + $table->string('description')->nullable(); $table->integer('maxCheck')->default(1); $table->timestamps(); }); diff --git a/resources/js/components/FormOptionItemComponent.vue b/resources/js/components/FormOptionItemComponent.vue index d459185..fc4a6ec 100644 --- a/resources/js/components/FormOptionItemComponent.vue +++ b/resources/js/components/FormOptionItemComponent.vue @@ -30,6 +30,7 @@ export default { }, methods: { handleKey(e) { + e && e.preventDefault(); if (e.keyCode === 13) { this.$emit('enter', this.option); } diff --git a/resources/js/components/FormQuestionComponent.vue b/resources/js/components/FormQuestionComponent.vue index 7b1eb40..7a1ae7b 100644 --- a/resources/js/components/FormQuestionComponent.vue +++ b/resources/js/components/FormQuestionComponent.vue @@ -2,57 +2,59 @@