Torann / laravel-currency

This provides Laravel with currency functions such as currency formatting and conversion using up-to-date exchange rates.
http://lyften.com/projects/laravel-currency
BSD 2-Clause "Simplified" License
395 stars 136 forks source link

Array to string conversion (SQL: insert into `answers` (`quiz_id`, `correct`, `answer`) values (45, 0, test 1)) #107

Open azhar39 opened 6 years ago

azhar39 commented 6 years ago

this is my controller public function quizAdd() { $question=Input::get('question'); $category_id=Input::get('category_id'); $type=Input::get('type'); // $quiz_id=Input::get('quiz_id'); $correct=Input::get('correct'); $answer=Input::get('answer'); // dd($correct);

    if (Request::isMethod('post')){
$q_id = DB::table('quizes')->insertGetId (array(
'question'=>$question,
'category_id'=>$category_id,
'type'=>$type));

foreach ($answer as $answer) {

if($correct==1){
$id = DB::table('answers')->insertGetId (array(
'quiz_id'=>$q_id,
'correct'=>$correct,
'answer'=>$answer));
              }

else {

$id = DB::table('answers')->insertGetId (array(
'quiz_id'=>$q_id,
'correct'=>$correct,
'answer'=>$answer));
 }

} } return redirect('content_dashboard')->with(compact('answer')); }

this is my view

                <div class="form-group">
                  <div class="col-sm-2">
               <select id="correct"class="form-control" name="correct[]">
                      <option value="0">correct?</option>
                      <option value="1">Yes</option>
                      <!-- <option value="0">No</option> -->
                      </select>
                  </div>
                  <div class="col-md-8 col-sm-8 col-xs-12">
                    <input class="form-control" type="text" placeholder=" Type the Answer" name="answer[]">
                  </div>
                </div>