This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| [Illuminate\Database\QueryException] | |
| SQLSTATE[23000]: Integrity constraint violation: 1217 Cannot delete or upda | |
| te a parent row: a foreign key constraint fails (SQL: drop table if exists | |
| `topics`) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| use Illuminate\Database\Schema\Blueprint; | |
| use Illuminate\Database\Migrations\Migration; | |
| class CreateTopicsTable extends Migration | |
| { | |
| /** | |
| * Run the migrations. | |
| * |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public function up() | |
| { | |
| Schema::create('topics', function (Blueprint $table) { | |
| $table->increments('id'); | |
| $table->string('title')->nullable(); | |
| $table->string('duration')->nullable(); | |
| $table->timestamps(); | |
| $table->softDeletes(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ouput of request | |
| "_token" => "AEVBOOFQToeqh0yhCiTdJR7peCerZeWpUAIKWwzj" | |
| "category_id" => "1" | |
| "topic_id" => "1" | |
| "question_text" => "question" | |
| "option1" => "ans1" | |
| "option2" => "ans2" | |
| "option3" => "ans3" | |
| "option4" => "ans4" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public function store(Request $request) | |
| { | |
| $ques = new Question(); | |
| $ques->question_text = $request['question_text']; | |
| $ques->code_snippet = $request['code_snippet']; | |
| $ques->answer_explanation = $request['answer_explanation']; | |
| $ques->more_info_link = $request['more_info_link']; | |
| $ques->category_id = $request['category_id']; | |
| $ques->topic_id = $request['topic_id']; | |
| dd($ques->save()); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 2 question_idIndex int(10) UNSIGNED Yes NULL Change Change Drop Drop | |
| Primary Primary | |
| Unique Unique | |
| Index Index | |
| More | |
| 3 option varchar(255) utf8_unicode_ci Yes NULL Change Change Drop Drop | |
| Primary Primary | |
| Unique Unique | |
| Index Index | |
| More |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public function store(Request $request) | |
| { | |
| $ques = new Question(); | |
| $ques->question_text = $request['question_text']; | |
| $ques->code_snippet = $request['code_snippet']; | |
| $ques->answer_explanation = $request['answer_explanation']; | |
| $ques->more_info_link = $request['more_info_link']; | |
| $ques->category_id = $request['category_id']; | |
| $ques->topic_id = $request['topic_id']; | |
| $ques->save(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| $data = []; | |
| $now = Carbon::now(); | |
| foreach($request->option as $key => $value) { | |
| $data[] = [ | |
| 'question_id' => $ques->id, | |
| 'answer' => $value, | |
| 'created_at' => Carbon::now(), | |
| 'updated_at' => Carbon::now(), | |
| ]; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| $ques = new Question(); | |
| $ques->question_text = $request->question_text; | |
| $ques->code_snippet = $request->code_snippet; | |
| $ques->answer_explanation = $request->answer_explanation; | |
| $ques->more_info_link = $request->more_info_link; | |
| $ques->category_id = $request->category_id; | |
| $ques->topic_id = $request->topic_id; | |
| $ques->save(); | |
| $data = []; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| -- phpMyAdmin SQL Dump | |
| -- version 4.5.4.1deb2ubuntu2 | |
| -- http://www.phpmyadmin.net | |
| -- | |
| -- Host: localhost | |
| -- Generation Time: Nov 15, 2017 at 07:18 AM | |
| -- Server version: 5.7.20-0ubuntu0.16.04.1 | |
| -- PHP Version: 7.0.22-0ubuntu0.16.04.1 | |
| SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO"; |