diff --git a/app/Http/Controllers/MasterData/LandController.php b/app/Http/Controllers/MasterData/LandController.php index 00446e4..21aebc5 100644 --- a/app/Http/Controllers/MasterData/LandController.php +++ b/app/Http/Controllers/MasterData/LandController.php @@ -7,6 +7,7 @@ use App\Models\LandDetails; use App\Models\Province; use Illuminate\Http\Request; +use Illuminate\Support\Facades\Auth; use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\Validator; @@ -98,10 +99,14 @@ public function store(Request $request) } DB::commit(); toast('Data berhasil disimpan', 'success')->position('top-right')->autoclose(3000); - return redirect()->route('master_data.lahan.index'); + + if (Auth::user()->role == 'admin') { + return redirect()->route('master_data.lahan.index'); + } + + return redirect()->route('lahan.index'); } catch (\Throwable $th) { DB::rollBack(); - dd($th->getMessage()); toast('Terjadi kesalahan', 'error')->position('top')->autoclose(3000); return redirect()->back(); } @@ -117,6 +122,7 @@ public function edit($id) 'lng' => $detail->lng, ]; }); + return view('master-data.lahan.edit', compact('id', 'provinces', 'land', 'landDetails')); } @@ -163,9 +169,9 @@ public function update(Request $request, $id) $polygon = json_decode($request->polygon, true); - if (isset($polygon[0])) { - $polygon = $polygon[0]; // Ambil array pertama jika ada - } + // if (isset($polygon[0])) { + // $polygon = $polygon[0]; // Ambil array pertama jika ada + // } if ($validator->fails()) { toast($validator->messages()->all()[0], 'error')->position('top')->autoclose(3000); @@ -195,7 +201,12 @@ public function update(Request $request, $id) } DB::commit(); toast('Data berhasil diubah', 'success')->position('top-right')->autoclose(3000); - return redirect()->back(); + + if (Auth::user()->role == 'admin') { + return redirect()->route('master_data.lahan.index'); + } + + return redirect()->route('lahan.index'); } catch (\Throwable $th) { DB::rollBack(); dd($th->getMessage()); diff --git a/resources/views/master-data/lahan/edit.blade.php b/resources/views/master-data/lahan/edit.blade.php index 693b03f..b8583cb 100644 --- a/resources/views/master-data/lahan/edit.blade.php +++ b/resources/views/master-data/lahan/edit.blade.php @@ -44,8 +44,9 @@

Edit Data Lahan

-
+ @csrf @method('PUT')