title: Saving Array, from blade to controller Laravel
body: <p>I want to save all of these data which is might be an array, into my answer table. I have tried so many ways but cant seem to find a correct solution.. can someone helped me thank you. I dont how to store the data from the answer(create.blade.php) into a database which is on the store function in the AnswerController as I dont didn't understand how to use that $key=> $value stuff. Im still learning as I really put my heart on Laravel. Can someone who is Laravel's expertise help me or guide me? Thankyou so much..</p>
  
  <p><strong>Question Model</strong></p>
  
  <pre class="lang-php prettyprint-override"><code>&lt;?php
  
  namespace App;
  
  use Illuminate\Database\Eloquent\Model;
  
  class Question extends Model
  {
      public function feedback()
      {
          return $this-&gt;belongsTo('App\Feedback','feedback_id');
      }
  
      public function answers()
      {
          return $this-&gt;hasMany('App\Answer');
      }
  
  }
  </code></pre>
  
  <p>Answer Model</p>
  
  <pre class="lang-php prettyprint-override"><code>&lt;?php
  
  namespace App;
  
  use Illuminate\Database\Eloquent\Model;
  
  class Answer extends Model
  {
      protected $fillable = ['question_id', 'feedback_type', 'answer'];
  
      public function question()
      {
          return $this-&gt;belongsTo('App\Answer','question_id');
      }
  
     /* public function user()
      {
          return $this-&gt;belongsTo('App\Answer','user_id');
      } */
  }
  </code></pre>
  
  <p><strong>Answer</strong> (create.blade.php)</p>
  
  <pre class="lang-html prettyprint-override"><code>&lt;form class="login100-form validate-form flex-sb flex-w" method="post" action="{{action('AnswerController@store')}}"&gt;
      &lt;span class="login100-form-title p-b-53"&gt;
          Survey Page
      &lt;/span&gt;
  
      @csrf,
      @foreach ($questions as $question)
          &lt;input type="hidden" class="form-control" name="question[]" value="{{$question-&gt;id}}"&gt;
          &lt;div class="form-group col-md-12"&gt;
              &lt;div class="txt1"&gt;
                  Soalan : {{$question-&gt;question_desc}}
              &lt;/div&gt;
          &lt;/div&gt;
  
          @if($question-&gt;question_type === 'rating')
              &lt;div class="form-group col-md-12"&gt;
                  &lt;span class="txt1"&gt;
                      Jawapan :
                      &lt;span class="rating"&gt;
                          &lt;input id="rating5[{{$question-&gt;id}}]" type="radio" name="answer[{{$question-&gt;id}}]"
                                 value="5"&gt;
                          &lt;label for="rating5[{{$question-&gt;id}}]"&gt;5&lt;/label&gt;
                          &lt;input id="rating4[{{$question-&gt;id}}]" type="radio" name="answer[{{$question-&gt;id}}]"
                                 value="4"&gt;
                          &lt;label for="rating4[{{$question-&gt;id}}]"&gt;4&lt;/label&gt;
                          &lt;input id="rating3[{{$question-&gt;id}}]" type="radio" name="answer[{{$question-&gt;id}}]"
                                 value="3"&gt;
                          &lt;label for="rating3[{{$question-&gt;id}}]"&gt;3&lt;/label&gt;
                          &lt;input id="rating2[{{$question-&gt;id}}]" type="radio" name="answer[{{$question-&gt;id}}]"
                                 value="2"&gt;
                          &lt;label for="rating2[{{$question-&gt;id}}]"&gt;2&lt;/label&gt;
                          &lt;input id="rating1[{{$question-&gt;id}}]" type="radio" name="answer[{{$question-&gt;id}}]"
                                 value="1"&gt;
                          &lt;label for="rating1[{{$question-&gt;id}}]"&gt;1&lt;/label&gt;
                      &lt;/span&gt;
                   &lt;/span&gt;
              &lt;/div&gt;
          @elseif($question-&gt;question_type === 'option')
              &lt;div class="form-group col-md-12"&gt;
                  Jawapan :
                  &lt;input type="radio" name="answer[{{$question-&gt;id}}]" value="yes"&gt;
                  &lt;label&gt;YES&lt;/label&gt;
                  &lt;input type="radio" name="answer[{{$question-&gt;id}}]" value="no"&gt;
                  &lt;label&gt;NO&lt;/label&gt;
              &lt;/div&gt;
          @elseif($question-&gt;question_type === 'text')
              &lt;div class="form-group col-md-12"&gt;
                  &lt;span class="txt1"&gt;
                      Jawapan :
                      &lt;textarea class="form-control input-sm" id="answer" rows="3" name="answer[{{$question-&gt;id}}]"&gt;&lt;/textarea&gt;
                   &lt;/span&gt;
              &lt;/div&gt;
          @endif
      @endforeach
      &lt;div class="container-login100-form-btn m-t-17"&gt;
          &lt;button class="login100-form-btn"&gt;
              Submit
          &lt;/button&gt;
      &lt;/div&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p><strong>AnswerController</strong></p>
  
  <pre class="lang-php prettyprint-override"><code>&lt;?php
  
  namespace App\Http\Controllers;
  
  namespace App\Http\Controllers;
  use App\Feedback;
  use App\Answer;
  use App\Question;
  use Illuminate\Http\Request;
  use Illuminate\Support\Facades\Redirect;
  
  class AnswerController extends Controller
  {
      /**
       * Display a listing of the resource.
       *
       * @return \Illuminate\Http\Response
       */
      public function index()
      {
          $questions = Question::all();
          return view('Answer.index',compact('questions'));
      }
  
      /**
       * Show the form for creating a new resource.
       *
       * @return \Illuminate\Http\Response
       */
      public function create()
      {
          $questions = Question::all();
          return view('Answer.create',compact('questions'));
      }
  
      /**
       * Store a newly created resource in storage.
       *
       * @param  \Illuminate\Http\Request  $request
       * @return \Illuminate\Http\Response
       */
      public function store(Request $request)
      {
         foreach ($request-&gt;question as $key =&gt; $value){
             $answer = new Answer();
             $answer -&gt; question_id = $value;
             $answer -&gt; answer = $request-&gt;input('answer');
             $answer -&gt; save();
         }
  
          return Redirect::back();
      }
  </code></pre>
  
  <p><strong>Route</strong></p>
  
  <pre class="lang-php prettyprint-override"><code>&lt;?php
  
  Route::resource('feedbacks','FeedbackController');
  Route::resource('questions','QuestionController');
  Route::resource('answers','AnswerController');
  Auth::routes();
  Route::get('/home', 'HomeController@index')-&gt;name('home');
  </code></pre>