This commit is contained in:
2026-04-16 16:40:17 +07:00
parent 5b5d8d6017
commit ee6e2efe17
+5 -2
View File
@@ -12,12 +12,15 @@ use App\Models\Map\Panen;
class PanenController extends Controller
{
public function index(): JsonResponse
public function index(Request $request): JsonResponse
{
Gate::authorize(['petani', 'fasilitator']);
$user = Auth::user();
$listPanen = Panen::where('farmer_id', $user->profile->id)->get();
$profile = $user->profile;
$profileId = $user->role === 'petani' ? $profile->id : $user->id;
$listPanen = Panen::when($profileId, fn($q,$v) => $q->where('farmer_id',$v))->get();
return response()->json($listPanen);
}