fix(master-land): fix function update data
This commit is contained in:
parent
1d2231f822
commit
78a67f401f
|
@ -7,6 +7,7 @@
|
||||||
use App\Models\LandDetails;
|
use App\Models\LandDetails;
|
||||||
use App\Models\Province;
|
use App\Models\Province;
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
|
use Illuminate\Support\Facades\Auth;
|
||||||
use Illuminate\Support\Facades\DB;
|
use Illuminate\Support\Facades\DB;
|
||||||
use Illuminate\Support\Facades\Validator;
|
use Illuminate\Support\Facades\Validator;
|
||||||
|
|
||||||
|
@ -98,10 +99,14 @@ public function store(Request $request)
|
||||||
}
|
}
|
||||||
DB::commit();
|
DB::commit();
|
||||||
toast('Data berhasil disimpan', 'success')->position('top-right')->autoclose(3000);
|
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) {
|
} catch (\Throwable $th) {
|
||||||
DB::rollBack();
|
DB::rollBack();
|
||||||
dd($th->getMessage());
|
|
||||||
toast('Terjadi kesalahan', 'error')->position('top')->autoclose(3000);
|
toast('Terjadi kesalahan', 'error')->position('top')->autoclose(3000);
|
||||||
return redirect()->back();
|
return redirect()->back();
|
||||||
}
|
}
|
||||||
|
@ -117,6 +122,7 @@ public function edit($id)
|
||||||
'lng' => $detail->lng,
|
'lng' => $detail->lng,
|
||||||
];
|
];
|
||||||
});
|
});
|
||||||
|
|
||||||
return view('master-data.lahan.edit', compact('id', 'provinces', 'land', 'landDetails'));
|
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);
|
$polygon = json_decode($request->polygon, true);
|
||||||
|
|
||||||
if (isset($polygon[0])) {
|
// if (isset($polygon[0])) {
|
||||||
$polygon = $polygon[0]; // Ambil array pertama jika ada
|
// $polygon = $polygon[0]; // Ambil array pertama jika ada
|
||||||
}
|
// }
|
||||||
|
|
||||||
if ($validator->fails()) {
|
if ($validator->fails()) {
|
||||||
toast($validator->messages()->all()[0], 'error')->position('top')->autoclose(3000);
|
toast($validator->messages()->all()[0], 'error')->position('top')->autoclose(3000);
|
||||||
|
@ -195,7 +201,12 @@ public function update(Request $request, $id)
|
||||||
}
|
}
|
||||||
DB::commit();
|
DB::commit();
|
||||||
toast('Data berhasil diubah', 'success')->position('top-right')->autoclose(3000);
|
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) {
|
} catch (\Throwable $th) {
|
||||||
DB::rollBack();
|
DB::rollBack();
|
||||||
dd($th->getMessage());
|
dd($th->getMessage());
|
||||||
|
|
|
@ -44,8 +44,9 @@
|
||||||
<h4 class="card-title mb-0">Edit Data Lahan</h4>
|
<h4 class="card-title mb-0">Edit Data Lahan</h4>
|
||||||
</div>
|
</div>
|
||||||
<div class="card-body">
|
<div class="card-body">
|
||||||
<form id="edit-form" action="{{ route('master_data.lahan.update', $land->id) }}" method="POST"
|
<form id="edit-form"
|
||||||
class="needs-validation" novalidate>
|
action="{{ Auth::user()->role == 'admin' ? route('master_data.lahan.update', $land->id) : route('lahan.update', $land->id) }}"
|
||||||
|
method="POST" class="needs-validation" novalidate>
|
||||||
@csrf
|
@csrf
|
||||||
@method('PUT')
|
@method('PUT')
|
||||||
<div class="modal-body">
|
<div class="modal-body">
|
||||||
|
|
|
@ -77,7 +77,7 @@ class="fw-medium link-primary">#VZ2101</a></td>
|
||||||
<td>
|
<td>
|
||||||
<div class="d-flex gap-2 justify-content-center">
|
<div class="d-flex gap-2 justify-content-center">
|
||||||
<div class="edit">
|
<div class="edit">
|
||||||
<a href="{{ route('master_data.lahan.edit', $land->id) }}"
|
<a href="{{ Auth::user()->role == 'admin' ? route('master_data.lahan.edit', $land->id) : route('lahan.edit', $land->id) }}"
|
||||||
class="btn btn-sm btn-warning edit-item-btn">Edit</a>
|
class="btn btn-sm btn-warning edit-item-btn">Edit</a>
|
||||||
</div>
|
</div>
|
||||||
<div class="remove">
|
<div class="remove">
|
||||||
|
|
|
@ -129,8 +129,9 @@
|
||||||
Route::prefix('data-lahan-petugas')->controller(LandController::class)->name('lahan.')->group(function () {
|
Route::prefix('data-lahan-petugas')->controller(LandController::class)->name('lahan.')->group(function () {
|
||||||
Route::get('/', 'index')->name('index');
|
Route::get('/', 'index')->name('index');
|
||||||
Route::get('/tambah', 'create')->name('create');
|
Route::get('/tambah', 'create')->name('create');
|
||||||
Route::post('/', 'store')->name('store');
|
Route::post('/tambah', 'store')->name('store');
|
||||||
Route::put('/{id}', 'update')->name('update');
|
Route::get('/edit/{id}', 'edit')->name('edit');
|
||||||
|
Route::put('/edit/{id}', 'update')->name('update');
|
||||||
Route::delete('/{id}', 'destroy')->name('destroy');
|
Route::delete('/{id}', 'destroy')->name('destroy');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue