Ben olsam şöyle bir yapı kurup ilerlerdim. İhtiyaca veya duruma göre değiştirmek gerekebilir tabi.
İlişkiyi tutacak modelim:
class Inspection extends Model
{
protected $table = "inspections";
protected $fillable = [
"checked_date",
"teacher_id",
"student_id",
"status"
];
protected $dates = [
"checked_date"
];
protected $casts = [
'checked_date' => 'datetime:Y-m-d',
];
public function teacher(): BelongsTo
{
return $this->belongsTo(Teacher::class);
}
public function student(): BelongsTo
{
return $this->belongsTo(Student::class);
}
}
Blade tarafında tablo oluşturma:
<table class="table">
<thead>
<tr>
<th>Name</th>
@foreach ($dates as $date)
<th>{{ $date }}</th>
@endforeach
</tr>
</thead>
<tbody>
@foreach ($students as $student)
<tr>
<td>{{ $student->full_name }}</td>
@foreach ($dates as $date)
<th>
<input type="checkbox" name="dayValue[{{ $student->id }}][{{ $date }}]">
</th>
@endforeach
</tr>
@endforeach
</tbody>
</table>