fix: sosial-ekonomi nested route & controller view
This commit is contained in:
@@ -42,25 +42,39 @@ class SosialEkonomiController extends Controller
|
||||
));
|
||||
}
|
||||
|
||||
public function index(Request $request): JsonResponse
|
||||
{
|
||||
$sosialEkonomi = SosialEkonomi::with([
|
||||
'petani',
|
||||
'pendapatanKomoditas',
|
||||
'pendapatanLuarPertanian',
|
||||
])
|
||||
->when($request->search, function ($query, $search) {
|
||||
$query->whereHas('petani', function ($petani) use ($search) {
|
||||
$petani->where('nama', 'like', "%{$search}%");
|
||||
});
|
||||
})
|
||||
->when($request->petani_id, fn ($query, $petaniId) => $query->where('petani_id', $petaniId))
|
||||
->orderBy('created_at', 'desc')
|
||||
->paginate($request->per_page ?? 10);
|
||||
public function index(Request $request, Petani $petani)
|
||||
{
|
||||
$sosialEkonomi = SosialEkonomi::with([
|
||||
'pendapatanKomoditas',
|
||||
'pendapatanLuarPertanian',
|
||||
])
|
||||
->where('petani_id', $petani->id)
|
||||
->first();
|
||||
|
||||
$komoditasPetani = collect();
|
||||
|
||||
$pendapatanKomoditasUtama = $sosialEkonomi?->pendapatanKomoditas
|
||||
->where('kategori', 'utama') ?? collect();
|
||||
|
||||
$pendapatanKomoditasLainnya = $sosialEkonomi?->pendapatanKomoditas
|
||||
->where('kategori', 'lainnya') ?? collect();
|
||||
|
||||
$pendapatanLuarPertanian = $sosialEkonomi?->pendapatanLuarPertanian ?? collect();
|
||||
|
||||
if ($request->expectsJson()) {
|
||||
return response()->json($sosialEkonomi);
|
||||
}
|
||||
|
||||
return view('produktivitas.petani.sosial-ekonomi.index', compact(
|
||||
'petani',
|
||||
'sosialEkonomi',
|
||||
'komoditasPetani',
|
||||
'pendapatanKomoditasUtama',
|
||||
'pendapatanKomoditasLainnya',
|
||||
'pendapatanLuarPertanian',
|
||||
));
|
||||
}
|
||||
|
||||
public function store(Request $request): JsonResponse|RedirectResponse
|
||||
{
|
||||
$validated = $this->validateData($request);
|
||||
|
||||
Reference in New Issue
Block a user