tanaman on profile id

This commit is contained in:
fauzgabriel@gmail.com 2026-04-15 14:07:51 +07:00
parent f8264a41cb
commit 0b4f88ab90

View File

@ -25,8 +25,9 @@ public function index(Request $request): AnonymousResourceCollection
if (!Gate::any(['petani', 'fasilitator'])) { if (!Gate::any(['petani', 'fasilitator'])) {
abort(403); abort(403);
} }
$user = Auth::user();
$profile = Auth::user()->profile; $profile = $user->profile;
$profileId = $user->role === 'petani' ? $profile->id : $request->profile_id;
$size = $request->integer('size') ?: 10; $size = $request->integer('size') ?: 10;
@ -35,6 +36,7 @@ public function index(Request $request): AnonymousResourceCollection
$search = strtolower($search); $search = strtolower($search);
$q->whereRaw('lower(nama) like ?', ["%{$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->status_kepemilikan, fn($q,$v) => $q->where('status_kepemilikan',$v))
->when($request->lahan_id, fn($q,$v) => $q->where('lahan_id',$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)) ->when($request->komoditas_id, fn($q,$v) => $q->where('komoditas_id',$v))