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))