I only want to display the latest data from the tanggal_ins that I have marked, how to?
And this is my query:
$cuti = DB::table('t_cuti as cuti')
->join('m_karyawan as kary', 'kary.nik', '=', 'cuti.nik')
->join('m_rumah_sakit as rs', 'rs.kd_rs', '=', 'kary.kd_rs')
->join('m_unit as unit', 'unit.kd_unit', '=', 'kary.kd_unit')
->join('m_jabatan as jab', 'jab.kd_jabatan', '=', 'kary.kd_jabatan')
->leftJoin('t_cuti_adjust as adj', function ($leftJoin) {
$leftJoin->on('adj.nik', '=', 'cuti.nik')
->latest();
})
->select('adj.tanggal_ins','cuti.saldo_cuti','kary.nik','kary.nm_karyawan','rs.nm_rs','unit.nm_unit','jab.nm_jabatan')
->whereYear('adj.tanggal_ins', '<', $year)
->orWhere('adj.tanggal_ins', null)
->get();
Thanks.
show only last record
, and the text saysdisplay the latest data
. OK, that is pretty clear. To do that in a DB query you would first sort your results, and then limit the number you retrieve. For egORDER BY created_at
, andLIMIT 2
. In Laravel query builder that would be for egorderBy()
andlimit()
(I linked to the docs already). But your query has no ordering, and no limiting ...