- Stop using laravel
- Take this course https://laracasts.com/series/php-for-beginners
- and https://laracasts.com/series/laravel-from-scratch-2017
- Come back to laravel
Feb 24, 2017
25
Level 13
How to update multiple field?
I successfully create the data with single request problem is that how can now update them problem with what it should be the route of "geteditform" and "postupdate" form should be my created controller
public function postmarkForm($reg_no = null,Request $request)
{
$s = Student::where('reg_no',$reg_no)->with('courses','courses.psubjects')->first();
$course_id = $s->courses->id;
$datetime = Carbon::now();
foreach ($request->subject as $key => $v)
{
$data = [
'course_id' => $course_id,
'subject_id' => $v,
'test_marks' => $request->test_marks [$key],
'mid_marks' => $request->mid_marks [$key],
'end_marks' => $request->end_marks [$key],
'student_id' => $s->id,
'updated_at' => $datetime,
'created_at' => $datetime
];
Mark::create($data);
}
return back();
}
and view for saving form
<form method="post" action="/acadmic/{{$s->reg_no}}/marks_upload" data-parsley-validate ="">
{{ csrf_field() }}
<table class="table table-bordered table-hover">
<thead>
<tr>
<th style="text-align: center;">Subject</th>
<th style="text-align: center;">Test Marks</th>
<th style="text-align: center;">Mid Marks</th>
<th style="text-align: center;">End Marks</th>
</tr>
</thead>
@foreach($s->courses->psubjects as $subject)
<tbody>
<tr>
<td class="col-md-3" >
<div class="form-group" >
<select class="form-control" id="subject[]" name="subject[]" required="">
<option value="{{ $subject->id}}">{{ $subject->name }}</option>
</select>
</div>
</td>
<td class="col-md-3">
<div class="form-group">
<input type="text" class="form-control" id="test_marks[]" name="test_marks[]" data-parsley-type="number" data-parsley-range="[0, 25]">
</div>
</td>
<td class="col-md-3">
<div class="form-group">
<input type="text" class="form-control" id="mid_marks" name="mid_marks[]" data-parsley-type="number" data-parsley-range="[0, 50]">
</div>
</td>
<td class="col-md-3">
<div class="form-group">
<input type="text" class="form-control" id="end_marks" name="end_marks[]" data-parsley-type="number" data-parsley-range="[0, 100]">
</div>
</td>
</tr>
</tbody>
@endforeach
</table>
<div class="col-md-4 col-md-offset-4">
<br>
<button type="submit" class="btn btn-primary btn-lg btn-block">Submit</button>
</div>
</form>
I have relationship marks belongs to (students, courses, subjects) and students belongs to(courses) and courses and subjects have pivot table(course_subject) here in this pic i have inserted value all in single request , i confused that what should be the route(getform and update form because here have 6 column value
Please or to participate in this conversation.