profil update dan gate tanaman

This commit is contained in:
Irwan Cahyono 2026-04-15 09:59:47 +07:00
parent 5845f491ce
commit 66ec20699c
2 changed files with 17 additions and 5 deletions

View File

@ -175,6 +175,7 @@ public function update(Request $request, string $id): JSONResponse
'file_kk' => ['nullable', 'file', 'mimes:jpg,jpeg,png,pdf', 'max:2048'], 'file_kk' => ['nullable', 'file', 'mimes:jpg,jpeg,png,pdf', 'max:2048'],
'file_ktp' => ['nullable', 'file', 'mimes:jpg,jpeg,png,pdf', 'max:2048'], 'file_ktp' => ['nullable', 'file', 'mimes:jpg,jpeg,png,pdf', 'max:2048'],
'desa_kelurahan_id' => ['nullable', 'exists:master_desa_kelurahan,id'], 'desa_kelurahan_id' => ['nullable', 'exists:master_desa_kelurahan,id'],
'email_verified_at' => ['nullable', 'date'],
]); ]);
if ($request->hasFile('file_kk')) { if ($request->hasFile('file_kk')) {
@ -195,6 +196,7 @@ public function update(Request $request, string $id): JSONResponse
$user->update([ $user->update([
'name' => $validated['nama'], 'name' => $validated['nama'],
'email' => $validated['email'], 'email' => $validated['email'],
'email_verified_at' => $validated['email_verified_at'],
'updated_by' => $user->id, 'updated_by' => $user->id,
]); ]);
}); });

View File

@ -22,7 +22,9 @@ class TanamanController extends Controller
*/ */
public function index(Request $request): AnonymousResourceCollection public function index(Request $request): AnonymousResourceCollection
{ {
Gate::authorize('petani'); if (!Gate::any(['petani', 'fasilitator'])) {
abort(403);
}
$profile = Auth::user()->profile; $profile = Auth::user()->profile;
@ -88,7 +90,9 @@ public function create()
*/ */
public function store(Request $request): JsonResponse public function store(Request $request): JsonResponse
{ {
Gate::authorize('petani'); if (!Gate::any(['petani', 'fasilitator'])) {
abort(403);
}
$profile = Auth::user()->profile; $profile = Auth::user()->profile;
$validated = $request->validate([ $validated = $request->validate([
@ -121,7 +125,9 @@ public function store(Request $request): JsonResponse
*/ */
public function show(string $id): JsonResponse public function show(string $id): JsonResponse
{ {
Gate::authorize('petani'); if (!Gate::any(['petani', 'fasilitator'])) {
abort(403);
}
$tanaman = Tanaman::findOrFail($id); $tanaman = Tanaman::findOrFail($id);
if ($tanaman->profile_id !== Auth::user()->profile->id) { if ($tanaman->profile_id !== Auth::user()->profile->id) {
@ -144,7 +150,9 @@ public function edit(string $id)
*/ */
public function update(Request $request, string $id): JsonResponse public function update(Request $request, string $id): JsonResponse
{ {
Gate::authorize('petani'); if (!Gate::any(['petani', 'fasilitator'])) {
abort(403);
}
$tanaman = Tanaman::findOrFail($id); $tanaman = Tanaman::findOrFail($id);
if ($tanaman->profile_id !== Auth::user()->profile->id) { if ($tanaman->profile_id !== Auth::user()->profile->id) {
return response()->json(['message' => 'Unauthorized'], 403); return response()->json(['message' => 'Unauthorized'], 403);
@ -177,7 +185,9 @@ public function update(Request $request, string $id): JsonResponse
*/ */
public function destroy(string $id): JsonResponse public function destroy(string $id): JsonResponse
{ {
Gate::authorize('petani'); if (!Gate::any(['petani', 'fasilitator'])) {
abort(403);
}
$tanaman = Tanaman::findOrFail($id); $tanaman = Tanaman::findOrFail($id);
if ($tanaman->profile_id !== Auth::user()->profile->id) { if ($tanaman->profile_id !== Auth::user()->profile->id) {
return response()->json(['message' => 'Unauthorized'], 403); return response()->json(['message' => 'Unauthorized'], 403);