header summary
This commit is contained in:
@@ -253,11 +253,47 @@ class PetaniLahanController extends Controller
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the specified resource from storage.
|
||||
*/
|
||||
public function destroy(string $id)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
public function summary(string $petaniId)
|
||||
{
|
||||
if (!Gate::any(['super_admin', 'admin', 'fasilitator'])) {
|
||||
abort(403);
|
||||
}
|
||||
|
||||
$petani = Petani::findOrFail($petaniId);
|
||||
|
||||
$lahan = Lahan::where('petani_id', $petaniId)
|
||||
->sum('luas_lahan');
|
||||
|
||||
$tanaman = Tanaman::whereHas('lahan', function ($query) use ($petaniId) {
|
||||
$query->where('petani_id', $petaniId);
|
||||
})->count();
|
||||
|
||||
$komoditas = Lahan::where('petani_id', $petaniId)
|
||||
->join('master_komoditas', 'map_lahan.komoditas_id', '=', 'master_komoditas.id')
|
||||
->select('master_komoditas.nama', DB::raw('count(*) as total'))
|
||||
->groupBy('master_komoditas.nama')
|
||||
->orderBy('total', 'desc')
|
||||
->first();
|
||||
|
||||
$kondisiLahan = Lahan::where('petani_id', $petaniId)
|
||||
->select('kondisi_tanaman', DB::raw('count(*) as total'))
|
||||
->groupBy('kondisi_tanaman')
|
||||
->orderBy('total', 'desc')
|
||||
->first();
|
||||
|
||||
return response()->json([
|
||||
'status' => 'success',
|
||||
'data' => [
|
||||
'lahan' => $lahan,
|
||||
'tanaman' => $tanaman,
|
||||
'komoditas' => $komoditas ? $komoditas->nama : null,
|
||||
'kondisi_lahan' => $kondisiLahan ? $kondisiLahan->kondisi_tanaman : null,
|
||||
],
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user