In your first query, there is no “where” clause.
In query builder…
->leftJoin('detail_data as detail_B', function ($join) {
$join->on('detail_A.id_jenisdata', '=', 'detail_B.id_jenisdata')
->where('detail_A.tahun','2018')
->where('detail_B.tahun','2019');
})
CLICK HERE to find out more related problems solutions.