diff --git a/app/Http/Controllers/Dashboard/DatatableController.php b/app/Http/Controllers/Dashboard/DatatableController.php index 7a1f857..934452a 100644 --- a/app/Http/Controllers/Dashboard/DatatableController.php +++ b/app/Http/Controllers/Dashboard/DatatableController.php @@ -209,16 +209,26 @@ public function location(Request $request){ $subLocationsCount = $data->subLocations->count(); if($subLocationsCount > 0){ - return $subLocationsCount. ' [Lihat]'; + return $subLocationsCount. ' [Lihat]'; }else{ return $subLocationsCount; } + }) + ->addColumn('issues', function ($data) { + $issueCount = $data->issues->count(); + + if($issueCount > 0){ + return $issueCount. ' [Lihat]'; + }else{ + return $issueCount; + } + }) ->addColumn('action', function ($data) { $showUrl = route('dashboard.locations.show', ['id' => encrypt_id($data->id)]); - $addSubLocationUrl = route('dashboard.sub.locations.create', ['location' => $data->slug]); + $addSubLocationUrl = route('dashboard.sub.locations.create', ['location' => encrypt_id($data->id)]); $editUrl = route('dashboard.locations.edit', ['id' => encrypt_id($data->id)]); @@ -250,7 +260,7 @@ public function location(Request $request){ return $dropdown; }) - ->rawColumns(['sub_locations', 'status', 'action']) + ->rawColumns(['sub_locations', 'issues', 'status', 'action']) ->make(true); } @@ -264,8 +274,7 @@ public function subLocation(Request $request){ $locationParam = $request->input('location', null); if($locationParam){ - $location = Location::where('slug', '=', $locationParam)->first(); - $data = SubLocation::with(['location'])->where('location_id', '=', $location->id)->get(); + $data = SubLocation::with(['location'])->where('location_id', '=', decrypt_id($locationParam))->get(); }else{ $data = SubLocation::with(['location'])->get(); } @@ -282,6 +291,16 @@ public function subLocation(Request $request){ return 'Aktif'; } }) + ->addColumn('issues', function ($data) { + $issueCount = $data->issues->count(); + + if($issueCount > 0){ + return $issueCount. ' [Lihat]'; + }else{ + return $issueCount; + } + + }) ->addColumn('action', function ($data) { $showUrl = route('dashboard.sub.locations.show', ['id' => encrypt_id($data->id)]); @@ -311,7 +330,7 @@ public function subLocation(Request $request){ return $dropdown; }) - ->rawColumns(['status', 'action']) + ->rawColumns(['issues', 'status', 'action']) ->make(true); } @@ -1685,6 +1704,8 @@ public function issueManagement(Request $request){ $classificationParam = $request->input('classification', null); $subClassificationParam = $request->input('sub_classification', null); + $locationParam = $request->input('location', null); + $subLocationParam = $request->input('sub_location', null); if($classificationParam){ $data = IssueManagement::with(['location', 'subLocation', 'classification', 'subClassification', 'enhancer', 'governmentAgencies'])->where('classification_id', decrypt_id($classificationParam))->get(); @@ -1692,6 +1713,12 @@ public function issueManagement(Request $request){ }else if($subClassificationParam){ $data = IssueManagement::with(['location', 'subLocation', 'classification', 'subClassification', 'enhancer', 'governmentAgencies'])->where('sub_classification_id', decrypt_id($subClassificationParam))->get(); + }else if($locationParam){ + $data = IssueManagement::with(['location', 'subLocation', 'classification', 'subClassification', 'enhancer', 'governmentAgencies'])->where('location_id', decrypt_id($locationParam))->get(); + + }else if($subLocationParam){ + $data = IssueManagement::with(['location', 'subLocation', 'classification', 'subClassification', 'enhancer', 'governmentAgencies'])->where('sub_location_id', decrypt_id($subLocationParam))->get(); + }else{ $data = IssueManagement::with(['location', 'subLocation', 'classification', 'subClassification', 'enhancer', 'governmentAgencies'])->get(); } diff --git a/app/Http/Controllers/Dashboard/LocationController.php b/app/Http/Controllers/Dashboard/LocationController.php index ab43854..f20c385 100644 --- a/app/Http/Controllers/Dashboard/LocationController.php +++ b/app/Http/Controllers/Dashboard/LocationController.php @@ -25,13 +25,12 @@ public function create(){ public function store(LocationRequest $request){ $validatedData = $request->validated(); - $validatedData['slug'] = Str::slug($validatedData['name']); $validatedData['enhancer_id'] = Auth::id(); $createdLocation = Location::create($validatedData); if($createdLocation){ - return redirect()->back()->with('success-status', 'Berhasil menambahkan lokus.'); + return redirect()->route('dashboard.locations.index')->with('success-status', 'Berhasil menambahkan lokus.'); }else{ return redirect()->back()->with('failed-status', 'Gagal menambahkan lokus.'); } @@ -48,7 +47,6 @@ public function edit($id){ public function update(LocationRequest $request, $id){ $validatedData = $request->validated(); - $validatedData['slug'] = Str::slug($validatedData['name']); $validatedData['enhancer_id'] = Auth::id(); $location = Location::findOrFail(decrypt_id($id)); diff --git a/app/Http/Controllers/Dashboard/SubClassificationController.php b/app/Http/Controllers/Dashboard/SubClassificationController.php index b817f6d..fff363e 100644 --- a/app/Http/Controllers/Dashboard/SubClassificationController.php +++ b/app/Http/Controllers/Dashboard/SubClassificationController.php @@ -30,8 +30,8 @@ public function create(Request $request){ ]; if($request->has('classification')){ - $classificationId = $request->query('classification'); - $viewData['classification'] = Classification::where('id', '=', decrypt_id($classificationId))->first(); + $classificationId = decrypt_id($request->query('classification')); + $viewData['classification'] = Classification::findOrFail($classificationId); $viewData['fromClassification'] = true; }else{ $viewData['classifications'] = Classification::all(); diff --git a/app/Http/Controllers/Dashboard/SubLocationController.php b/app/Http/Controllers/Dashboard/SubLocationController.php index 2d0d7e2..bc45176 100644 --- a/app/Http/Controllers/Dashboard/SubLocationController.php +++ b/app/Http/Controllers/Dashboard/SubLocationController.php @@ -30,8 +30,8 @@ public function create(Request $request){ ]; if($request->has('location')){ - $locationSlug = $request->query('location'); - $viewData['location'] = Location::where('slug', '=', $locationSlug)->first(); + $locationId = decrypt_id($request->query('location')); + $viewData['location'] = Location::findOrFail($locationId); $viewData['fromLocation'] = true; }else{ $viewData['locations'] = Location::all(); @@ -42,13 +42,12 @@ public function create(Request $request){ public function store(SubLocationRequest $request){ $validatedData = $request->validated(); - $validatedData['slug'] = Str::slug($validatedData['name']); $validatedData['enhancer_id'] = Auth::id(); $createdSubLocation = SubLocation::create($validatedData); if($createdSubLocation){ - return redirect()->back()->with('success-status', 'Berhasil menambahkan sub lokus.'); + return redirect()->route('dashboard.sub.locations.index')->with('success-status', 'Berhasil menambahkan sub lokus.'); }else{ return redirect()->back()->with('failed-status', 'Gagal menambahkan sub lokus.'); } @@ -66,7 +65,6 @@ public function edit($id){ public function update(SubLocationRequest $request, $id){ $validatedData = $request->validated(); - $validatedData['slug'] = Str::slug($validatedData['name']); $validatedData['enhancer_id'] = Auth::id(); $subLocation = SubLocation::findOrFail(decrypt_id($id)); diff --git a/app/Models/Location.php b/app/Models/Location.php index fb70294..69bb28b 100644 --- a/app/Models/Location.php +++ b/app/Models/Location.php @@ -18,4 +18,8 @@ class Location extends Model public function subLocations(){ return $this->hasMany(SubLocation::class, 'location_id', 'id'); } + + public function issues(){ + return $this->hasMany(IssueManagement::class, 'location_id', 'id'); + } } diff --git a/app/Models/SubLocation.php b/app/Models/SubLocation.php index 5535896..9ab94f0 100644 --- a/app/Models/SubLocation.php +++ b/app/Models/SubLocation.php @@ -19,4 +19,8 @@ class SubLocation extends Model public function location(){ return $this->belongsTo(Location::class, 'location_id', 'id'); } + + public function issues(){ + return $this->hasMany(IssueManagement::class, 'sub_location_id', 'id'); + } } diff --git a/resources/views/dashboard/locations/create.blade.php b/resources/views/dashboard/locations/create.blade.php index 08a6a81..776fc65 100644 --- a/resources/views/dashboard/locations/create.blade.php +++ b/resources/views/dashboard/locations/create.blade.php @@ -12,14 +12,14 @@