Tuesday, April 4, 2017

Laravel 5.4 - Send array from form to controller

I have a model Testcase in my database which has a field called "testcaseOrder". I render all Testcase models into a form and implemented some logic, so I can rearrange the order by using drag & drop and then update the models with the new order.

<form id="store" class="center" method="POST" action="" enctype="multipart/form-data">

  

  <ul id="sortable" class="connectedSortable form-group">
      @foreach($AllTestcases as $testcase)
          <li class="ui-state-default" name="testcases[]" id="" value=""></li>
      @endforeach
  </ul>

  <div class="form-group">
      <button type="submit" id="save" class="btn btn-default">Speichern</button>
  </div>

  @include('partials.errors')

</form>

After submitting the form I try to access the values in my controller like this:

public function updateOrder($scenario_id)
{
    dd(request('testcases'));
    ...
}

However, I get null back as result. What am I doing wrong?


Note: $testcase->testcaseOrder is of type integer



via Black

Advertisement