我尝试根据'Jadwal_kuliah'和'khs'表过滤数据,但发现错误“类stdClass的对象无法转换为字符串”:
function jadwal_kuliah_json()
{
$nim = Auth::guard('mahasiswa')->user()->nim;
$tahun_akademik = \DB::table('tahun_akademik')->where('status', 'y')->first();
$kelas = \DB::table('khs')
->select('kode_kelas')
->where('nim', $nim)
->get();
$jadwal = \DB::table('jadwal_kuliah')
->join('khs', 'jadwal_kuliah.kode_mk', '=', 'khs.kode_mk')
->where('jadwal_kuliah.kode_kelas', $kelas)
->where('khs.nim', $nim)
->select('matakuliah.nama_mk', 'jadwal_kuliah.hari', 'jam_kuliah.jam', 'ruangan.nama_ruangan', 'dosen.nama', 'kelas.nama_kelas')
->get();
return Datatables::of($jadwal)->make(true);
}
JSON
{
"id": 36,
"kode_kelas": "TI18A",
"hari": "senin",
"kode_mk": "TI001",
"nidn": "15110185",
"jam": "1",
"kode_jurusan": "ifd3",
"kode_ruangan": "LBKom",
"kode_tahun_akademik": "20182",
"semester": 1,
"created_at": "2019-02-28 15:02:52",
"updated_at": "2019-02-28 15:02:52"
}
需要更改什么?
答案 0 :(得分:1)
$kelas
是一个集合,您将其作为字符串条件传递给:
->where('jadwal_kuliah.kode_kelas',$kelas)
首先使用first()
返回一个对象,如:
$kelas = \DB::table('khs')
->select('kode_kelas')
->where('nim',$nim)
->first();
然后,您必须像这样获取属性:
->where('jadwal_kuliah.kode_kelas',$kelas->kode_kelas)