here in this code i have passed the hardcoded value of month if i remove january it accepts december i.e last row how to solve this issue
controller
public function storeLeave(Request $request){
$admin= new Admin();
$admin->employee_name=$request->input('employee_name');
$admin->month=$request->input('month_JANUARY');
$admin->earned_leave=$request->input('earned_leave_JANUARY');
$admin->casual_leave=$request->input('casual_leave_JANUARY');
$admin->sick_leave=$request->input('sick_leave_JANUARY');
$admin->save();
}
blade file (table)
<table class="table table-bordered table-striped text-center" id="adminTable">
<thead>
<tr>
<th class="text-center">MONTHS</th>
<th class="text-center">EARNED LEAVE</th>
<th class="text-center">CASUAL LEAVE</th>
<th class="text-center">SICK LEAVE</th>
</tr>
</thead>
<tbody>
@foreach($months as $month)
<tr>
<td> <input readonly value="{{$month}}-<?php echo date("Y"); ?>" name="month_{{$month}}" id="month" style="background:none; border: none;"> </td>
<td> <input type="text" style="background:none; border: none " name="earned_leave_{{$month}}" id="earned_leave" ></td>
<td> <input type="text" style="background:none; border: none" name="casual_leave_{{$month}}" id="casual_leave"></td>
<td> <input type="text" style="background:none; border: none" name="sick_leave_{{$month}}" id="sick_leave"></td>
<td>
<input type="submit" class="btn btn-success" name="submit" id="add_leave" value="ADD">
<input type="hidden" name="_method" value="POST">
</td>
</tr>
@endforeach
</tbody>
</table>
2
Answers
try this
You must use a for loop inserting in database. The code below is the example on how you handle the for loop. Happy Coding.