jhutto
1 year ago

Form patch submit only returning last record of @foreach in form

Posted 1 year ago by jhutto

I've create a edit form that is posting with patch method. I have a @foreach that creates the items in a table. When the form is submitted and I check the $request output it only returns the last entry from the @foreach loop. Can someone show me how to get all the values for each line item in the @foreach table

This is a simplified version of the form.

<!-- form user info -->
<div class="card card-outline-secondary">
<div class="card-header">
<h3 class="mb-0">Course Tuition</h3>
</div>
<div class="card-body">
 <form method="Post" action="/courses/{{ $Courseid }}" >
     @method('Patch')
     @csrf
                              
<div class="form-group col-md-12">
     <table id="Tuitions" class="table table-striped table-bordered">
               <thead><tr>
               <th style="width: 10%;text-align:center;">TuitionType</th>
               <th style="width: 30%;text-align:center;">TuitionDesc</th>
               <th style="width: 20%;text-align:center;">ClassFee</th>
               <th style="width: 20%;text-align:center;">HomeOfficeFee</th>
                <th style="width: 20%;text-align:center;">MaterialsFee</th>
                </tr></thead     
               @foreach ($Tuitions as $key=>$value)
                <tr>
        <td><input type="text" id="TuitionType" name="TuitionType" style="text-align:center;"  value="{{ $value->id }} {{ $value->TuitionType }}"></input></td>
            <td><input type="text" id="TuitionDesc" name="TuitionDesc"  style="width:350px" value="{{ $value->id }} {{ $value->TuitionDesc }}></td>
           <td><input type="text" id="ClassFee" name="ClassFee" style="text-align:center;" value="{{ $value->id }} {{ $value->ClassFee }}></td>
            <td><input type="text" id="HomeOfficeFee" name="HomeOfficeFee" style="text-align:center;" value="{{ $value->id }} {{ $value->HomeOfficeFee }}>/td>
            <td><input type="text" id="MaterialsFee" name="MaterialsFee" style="text-align:center;" value="{{ $value->id }} {{ $value->MaterialsFee }}></td>
                    @endforeach
              </table>
</div>
             <div class="form-row">
              <div class="form-group col-lg-9" Style="height:50px;margin-left: 25px;">
               <input type="submit" class="btn btn-primary btn-lg" value="Save Changes">
                  <a href="/registrations/courses/{{$course[0]->SemesterID}}" class="btn btn-secondary btn-lg" role="button">Cancel</a>
               </div>
</div>
</form>
                        
                        </div>
                    </div>

Please sign in or create an account to participate in this conversation.