diff --git a/app/Http/Controllers/Dashboard/DatatableController.php b/app/Http/Controllers/Dashboard/DatatableController.php index d9af561..daad262 100644 --- a/app/Http/Controllers/Dashboard/DatatableController.php +++ b/app/Http/Controllers/Dashboard/DatatableController.php @@ -402,10 +402,20 @@ public function governmentAgency(Request $request){ if ($request->ajax()) { $data = GovernmentAgency::with(['issues'])->get(); + $newData = $request->input('new_data', null); + return DataTables::of($data) ->addIndexColumn() + ->addColumn('name', function ($data) use ($newData) { + + if(filled($newData) && decrypt_id($newData) == $data->id){ + return 'Baru'. $data->name; + }else{ + return $data->name; + } + }) ->addColumn('short_name', function ($data) { - return filled($data->short_name) ? $data->short_name : '-'; + return filled($data->short_name) ? $data->short_name : 'Belum ditambahkan'; }) ->addColumn('issues', function ($data) { $issueCount = $data->issues->count(); @@ -446,7 +456,7 @@ public function governmentAgency(Request $request){ return $dropdown; }) - ->rawColumns(['issues', 'action']) + ->rawColumns(['name', 'short_name', 'issues', 'action']) ->make(true); } diff --git a/app/Http/Controllers/Dashboard/GovernmentAgencyController.php b/app/Http/Controllers/Dashboard/GovernmentAgencyController.php index ca942df..2afbc37 100644 --- a/app/Http/Controllers/Dashboard/GovernmentAgencyController.php +++ b/app/Http/Controllers/Dashboard/GovernmentAgencyController.php @@ -13,13 +13,14 @@ class GovernmentAgencyController extends Controller { public function index(){ return view('dashboard.government-agencies.index', [ - 'title' => 'OPD' + 'title' => 'Data OPD', + 'new_data' => session()->get('new_data', null), ]); } public function create(){ return view('dashboard.government-agencies.create', [ - 'title' => 'Tambah OPD' + 'title' => 'Buat OPD Baru' ]); } @@ -27,11 +28,12 @@ public function store(GovernmentAgencyRequest $request){ $validatedData = $request->validated(); $validatedData['enhancer_id'] = Auth::id(); - $createdGovernmentAgency = GovernmentAgency::create($validatedData); + try{ + $createdGovernmentAgency = GovernmentAgency::create($validatedData); - if($createdGovernmentAgency){ - return redirect()->route('dashboard.government.agencies.index')->with('success-status', 'Berhasil menambahkan OPD.'); - }else{ + return redirect()->route('dashboard.government.agencies.index')->with('success-status', 'Berhasil membuat OPD baru.') + ->with('new_data', encrypt_id($createdGovernmentAgency->id)); + }catch(\Exception $e){ return redirect()->back()->with('failed-status', 'Gagal menambahkan OPD'); } } @@ -53,7 +55,7 @@ public function update(GovernmentAgencyRequest $request, $id){ $updatedGovernmentAgency = $governmentAgency->update($validatedData); if($updatedGovernmentAgency){ - return redirect()->back()->with('success-status', 'Berhasil mengubah OPD.'); + return redirect()->route('dashboard.government.agencies.show', ['id' => encrypt_id($governmentAgency->id)])->with('success-status', 'Berhasil mengubah OPD.'); }else{ return redirect()->back()->with('failed-status', 'Gagal mengubah OPD'); } diff --git a/app/Models/GovernmentAgency.php b/app/Models/GovernmentAgency.php index 1890727..94f1ee3 100644 --- a/app/Models/GovernmentAgency.php +++ b/app/Models/GovernmentAgency.php @@ -25,4 +25,8 @@ public function issues() ->using(IssueManagementGovernmentAgency::class) ->withTimestamps(); } + + public function enhancer(){ + return $this->belongsTo(User::class, 'enhancer_id', 'id'); + } } diff --git a/resources/views/dashboard/government-agencies/create.blade.php b/resources/views/dashboard/government-agencies/create.blade.php index 6b48cc1..3d81e5b 100644 --- a/resources/views/dashboard/government-agencies/create.blade.php +++ b/resources/views/dashboard/government-agencies/create.blade.php @@ -10,7 +10,10 @@
Masukkan informasi yang diperlukan untuk membuat OPD.
+