Hey
The insert method is used for database inserts, not Eloquent.
Use Mark::create($data) and set the fillable fields in the model (https://laravel.com/docs/5.4/eloquent#mass-assignment)
Regards,
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
I have tables (marks,students,subjects,courses) marks belongs to (students,subjects,courses) and i inserting data in marks using foreach method here is my inserting controller method
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 ($s->courses->psubjects as $sub)
{
$data = [
'course_id' => $course_id,
'subject_id' => $sub->id,
'test_marks' => $request->test_marks,
'mid_marks' => $request->mid_marks,
'end_marks' => $request->end_marks,
'student_id' => $s->id,
'updated_at' => $datetime,
'created_at' => $datetime,
];
Mark::insert($data);
}
return back();
}
and here is marks table
Schema::create('marks', function (Blueprint $table) {
$table->increments('id');
$table->integer('course_id')->unsigned()->index();
$table->integer('subject_id')->unsigned()->index();
$table->integer('student_id')->unsigned()->index();
$table->float('test_marks')->nullable();
$table->float('mid_marks')->nullable();
$table->float('end_marks')->nullable();
$table->timestamps();
});
}
and here is my inserting view
<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" name="test_marks" id="test_marks" data-parsley-type="number">
</div>
</td>
<td class="col-md-3">
<div class="form-group">
<input type="text" class="form-control" name="mid_marks" id="mid_marks" data-parsley-type="number">
</div>
</td>
<td class="col-md-3">
<div class="form-group">
<input type="text" class="form-control" name="end_marks" id="end_marks" data-parsley-type="number">
</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>
and when i insert one time here is my database marks table
https://www.dropbox.com/s/68240v5bfvv8xqs/1.PNG?dl=0
problem is that how can i update this i mean what is route for getting updating form
thanks
Please or to participate in this conversation.