diff --git a/app/Http/Controllers/Api/ProfileController.php b/app/Http/Controllers/Api/ProfileController.php index 56cdf69..c02b7a5 100644 --- a/app/Http/Controllers/Api/ProfileController.php +++ b/app/Http/Controllers/Api/ProfileController.php @@ -133,7 +133,13 @@ class ProfileController extends Controller abort(403); } - $profile = Profile::with('desaKelurahan')->where('user_id', Auth::id())->first(); + $user = Auth::user(); + $profile = $user->profile; + $profileId = $user->role === 'petani' ? $profile->id : $id; + + $profile = Profile::with('desaKelurahan') + ->when($profileId, fn($q,$v) => $q->where('id',$v)) + ->where('user_id', Auth::id())->first(); return response()->json(new ProfileResource($profile)); }