From 0b4f88ab90152a394f45974c2a08174c617cd49d Mon Sep 17 00:00:00 2001 From: "fauzgabriel@gmail.com" Date: Wed, 15 Apr 2026 14:07:51 +0700 Subject: [PATCH] tanaman on profile id --- app/Http/Controllers/Api/TanamanController.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/app/Http/Controllers/Api/TanamanController.php b/app/Http/Controllers/Api/TanamanController.php index 1064317..841f2bc 100644 --- a/app/Http/Controllers/Api/TanamanController.php +++ b/app/Http/Controllers/Api/TanamanController.php @@ -25,8 +25,9 @@ public function index(Request $request): AnonymousResourceCollection if (!Gate::any(['petani', 'fasilitator'])) { abort(403); } - - $profile = Auth::user()->profile; + $user = Auth::user(); + $profile = $user->profile; + $profileId = $user->role === 'petani' ? $profile->id : $request->profile_id; $size = $request->integer('size') ?: 10; @@ -35,6 +36,7 @@ public function index(Request $request): AnonymousResourceCollection $search = strtolower($search); $q->whereRaw('lower(nama) like ?', ["%{$search}%"]); }) + ->when($profileId, fn($q,$v) => $q->where('profile_id',$v)) ->when($request->status_kepemilikan, fn($q,$v) => $q->where('status_kepemilikan',$v)) ->when($request->lahan_id, fn($q,$v) => $q->where('lahan_id',$v)) ->when($request->komoditas_id, fn($q,$v) => $q->where('komoditas_id',$v))