tabel relasi tidak dapat memunculkan isi dari tabel
saya ingin menampilkan tabel nilai mahasiswa dimana satu mahasiswa memiliki banyak nilai dari beberapa mata kuliah. Mohon bantuannya
controller

controller
public function nilai($Nim) { $Mahasiswa = Mahasiswa::with('kelas')->where('nim', $Nim)->first(); $matkul = Mahasiswa_MataKuliah::with('matakuliah')->where('mahasiswa_id', ($Mahasiswa->mahasiswa_id))->get(); return view('mahasiswa.nilai', ['Mahasiswa' => $Mahasiswa, 'matakuliah' => $matkul]); }models
<?php namespace App\Models; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; class Mahasiswa_MataKuliah extends Model { use HasFactory; protected $table = 'matakuliah_mahasiswa'; protected $fillable = ['mahasiswa_id', 'matakuliah_id', 'nilai', ]; public function mahasiswa() { return $this->belongsTo(Mahasiswa::class, 'mahasiswa_id', 'id_mahasiswa'); } public function matakuliah() { return $this->belongTo(Matakuliah::class, 'matakuliah_id'); } }seeder
<?php namespace Database\Seeders; use Illuminate\Database\Seeder; use Illuminate\Support\Facades\DB; class MataKuliahSeeder extends Seeder { /** * Run the database seeds. * * @return void */ public function run() { $matkul = [ [ 'nama_matkul' => 'Pemrograman Berbasis Objek', 'sks' => 3, 'jam' => 6, 'semester' => 4, ], [ 'nama_matkul' => 'Pemrograman Web Lanjut', 'sks' => 3, 'jam' => 6, 'semester' => 4, ], [ 'nama_matkul' => 'Basis Data Lanjut', 'sks' => 3, 'jam' => 4, 'semester' => 4, ], [ 'nama_matkul' => 'Praktikum Basis Data Lanjut', 'sks' => 3, 'jam' => 6, 'semester' => 4, ], ]; DB::table('matakuliah')->insert($matkul); } }
<?php namespace Database\Seeders; use Illuminate\Database\Seeder; use Illuminate\Support\Facades\DB; class MataKuliahMahasiswaSeeder extends Seeder { /** * Run the database seeds. * * @return void */ public function run() { $data = [ [ 'mahasiswa_id' => 1, 'matakuliah_id' => 1, 'nilai' => 88 ], [ 'mahasiswa_id' => 1, 'matakuliah_id' => 2, 'nilai' => 87 ], [ 'mahasiswa_id' => 1, 'matakuliah_id' => 3, 'nilai' => 86 ], [ 'mahasiswa_id' => 1, 'matakuliah_id' => 4, 'nilai' => 90 ], [ 'mahasiswa_id' => 3, 'matakuliah_id' => 1, 'nilai' => 88 ], [ 'mahasiswa_id' => 3, 'matakuliah_id' => 2, 'nilai' => 93 ], [ 'mahasiswa_id' => 3, 'matakuliah_id' => 3, 'nilai' => 85 ], [ 'mahasiswa_id' => 3, 'matakuliah_id' => 4, 'nilai' => 80 ], ]; DB::table('matakuliah_mahasiswa')->insert($data); } }blade
@extends('mahasiswa.layout') @section('content') <div class="row"> <div class="col-lg-12 margin-tb"> <div class="justify-content-center align-items-center"> <div class="d-flex justify-content-center mt-2"> <h2>JURUSAN TEKNOLOGI INFORMASI</h2> </div> <div class="d-flex justify-content-center my-4"> <h1 class="text-center">KARTU HASIL STUDI (KHS)</h1> </div> </div> </div> <div class="text-left"> <p><b>Nama : </b>{{ $Mahasiswa->nama }}</p> <p><b>Nama : </b>{{ $Mahasiswa->nim }}</p> <p><b>Nama : </b>{{ $Mahasiswa->kelas->nama_kelas }}</p> </div> <table class="table table-bordered"> <tr> <th>Mata Kuliah</th> <th>SKS</th> <th>Semester</th> <th>Nilai</th> </tr> @foreach ($matakuliah as $matkul) <tr> <td>{{ $matkul->matakuliah->nama_matkul }}</td> <td>{{ $matkul->matakuliah->sks }}</td> <td>{{ $matkul->matakuliah->semester }}</td> <td>{{ $matkul->nilai }}</td> </tr> @endforeach </table> <a class="btn btn-success" href="{{ route('mahasiswa.index') }}">Kembali</a> </div> @endsection
1 Kontribusi 0 Poin
atau respon:
Jawaban
Belum ada Jawaban, jadi yang pertama
Login untuk gabung berdiskusiPertanyaan Lainnya
Top Kontributor
- @ahanafi
813 Kontribusi 551 Poin
- @Nandar
648 Kontribusi 204 Poin
- @dianarifr
642 Kontribusi 316 Poin
- @Saputroandhi
509 Kontribusi 162 Poin
- @dodipsitorus
412 Kontribusi 145 Poin