Skip to content

Commit

Permalink
Merge pull request sebastianbergmann#105 from sheby460/dino
Browse files Browse the repository at this point in the history
delete
  • Loading branch information
sheby460 authored Jul 25, 2024
2 parents 37a9fef + 8b899ce commit af45f9f
Show file tree
Hide file tree
Showing 9 changed files with 72 additions and 33 deletions.
25 changes: 15 additions & 10 deletions app/Http/Controllers/CcbrtRelationController.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,15 +79,20 @@ public function edit($id)
public function editRelationData(Request $request,$id){

}

public function destroy(string $id)
{
$relate = CcbrtRelation::find($id);

$relate->update([
'delete_status' => 1
]);

return redirect()->route('ccbrt_relation.index')->with('success', 'deleted successfully.');
}
{
$relate = CcbrtRelation::find($id);

if (!$relate) {
return redirect()->route('ccbrt_relation.index')->with('error', 'Record not found.');
}

$relate->delete();

return redirect()->route('ccbrt_relation.index')->with('success', 'Record deleted successfully.');
}




}
12 changes: 7 additions & 5 deletions app/Http/Controllers/HealthDetailsController.php
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use App\Models\HealthDetails;
use Illuminate\Support\Facades\Request as FacadesRequest;
use Illuminate\Support\Facades\Validator;
use RealRashid\SweetAlert\Facades\Alert;

class HealthDetailsController extends Controller
{
/**
Expand Down Expand Up @@ -79,7 +76,6 @@ public function updateHealthDetails(Request $request, string $id){
'errors' => $validator->errors(),
]);
}

$healthData = HealthDetails::findOrFail($id);
$healthData->update([
'physical_disability' => $request->input('physical_disability'),
Expand All @@ -96,8 +92,10 @@ public function updateHealthDetails(Request $request, string $id){
}

public function deleteHealthData(string $id){
$health = HealthDetails::find($id);
$health = HealthDetails::findOrFail($id);
$health->delete();


if(!$health){
return response()->json([
'status' => 400,
Expand All @@ -108,6 +106,10 @@ public function deleteHealthData(string $id){
$health->update([
'delete_status' => 1
]);
Alert::success('Deleted', 'Health detail deleted successfully.');

return redirect()->route('health-details.index');
}


}
2 changes: 1 addition & 1 deletion app/Http/Controllers/IctAccessController.php
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ public function store(Request $request)
// Success alert and redirect

Alert::success('IT access form request submitted successfully', 'IT access Request Added');
return redirect()->route('form.index')->with('success', 'ICT Access Resource created successfully.');
return redirect()->route('request.index')->with('success', 'ICT Access Resource created successfully.');
dd(1234); });
} catch (\Exception $e) {
// Log the exact error message for better debugging
Expand Down
30 changes: 19 additions & 11 deletions resources/views/ccbrt_relation/index.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -139,13 +139,22 @@ class="nav-link">Language</a> </li>
class="text-warning" title="Edit">
<i class="fas fa-edit"></i>
</a>

<!-- Delete button -->
<a href="#"
class="text-danger ms-2 delete-btn"
data-id="{{ $relation->id }}"
title="Delete">
<i class="fas fa-trash-alt"></i>
</a>
<form
action="{{ route('ccbrt_relation.destroy', $relation->id) }}"
method="POST" style="display: inline;"
class="delete-form">
@csrf
@method('DELETE')
<button type="button"
class="btn text-danger delete-btn"
title="Delete">
<i class="fas fa-trash-alt"
style="cursor: pointer;"></i>
</button>
</form>

</td>
</tr>
@endforeach
Expand All @@ -168,10 +177,9 @@ class="text-danger ms-2 delete-btn"
// Handle delete button click
document.querySelectorAll('.delete-btn').forEach(button => {
button.addEventListener('click', function(event) {
event.preventDefault(); // Prevent default link behavior
event.preventDefault(); // Prevent default button behavior
const id = this.getAttribute('data-id');
const deleteUrl = `/ccbrt-relation/delete/${id}`;
const form = this.closest('form');
Swal.fire({
title: 'Are you sure?',
Expand All @@ -184,8 +192,8 @@ class="text-danger ms-2 delete-btn"
cancelButtonText: 'No, cancel!',
}).then((result) => {
if (result.isConfirmed) {
// Redirect to delete route
window.location.href = deleteUrl;
// Submit the form
form.submit();
}
});
});
Expand Down
4 changes: 2 additions & 2 deletions resources/views/family-details/edit.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<div class="container">
<div class="row flex-lg-nowrap">

<div class="col">
{{-- <div class="col">
<div class="row">
<div class="col mb-3">
<div class="card">
Expand Down Expand Up @@ -165,7 +165,7 @@ function handleProfilePictureChange(input) {
</div>
<!-- Add other content for profile page here -->
</div>
</div>
</div> --}}
</div>
</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion resources/views/family-details/index.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ class="nav-link">Language</a></li>
<td>{{ $detail->DOB }}</td>
<td>{{ $detail->occupation }}</td>
<td>
<a href="{{ route('family-details.index', $detail->id) }}"
<a href="{{ route('family-details.edit', $detail->id) }}"
class="btn btn-sm p-0"
style="border: none; background: none;"
title="Edit">
Expand Down
16 changes: 15 additions & 1 deletion resources/views/health-details/index.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ class="btn btn-sm p-0"style="border: none; background: none;"
<i class="fas fa-edit text-primary"></i>
</a>

<form
{{-- <form
action="{{ route('health-details.delete', $health->id) }}"
method="POST" style="display:inline;">
@csrf
Expand All @@ -213,6 +213,20 @@ class="btn btn-sm p-0"style="border: none; background: none;"
title="Delete">
<i class="fas fa-trash-alt text-danger"></i>
</button>
</form> --}}


<form
action="{{ route('health-details.delete', $health->id) }}"
method="POST" style="display:inline;"
class="delete-health-form">
@csrf
@method('DELETE')
<button type="submit" class="btn btn-sm p-0"
style="border: none; background: none;"
title="Delete">
<i class="fas fa-trash-alt text-danger"></i>
</button>
</form>
</td>
</tr>
Expand Down
8 changes: 8 additions & 0 deletions resources/views/partials/sidebar.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,14 @@ class="{{ request()->routeIs('request.index') ? 'active' : '' }}">My Requests</a
<span>Departments</span></a>
</li>
@endcan
{{-- Users --}}
{{-- @can('view users')
<li class="{{ request()->routeIs('viewuser.index') ? 'active' : '' }}">
<a href="{{ route('viewuser.index') }}"><i class="fas fa-users"></i>
<span>Users</span></a>
</li>
@endcan --}}


{{-- NHIF --}}
@can('view nhif')
Expand Down
6 changes: 4 additions & 2 deletions routes/web.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,17 +77,19 @@


Route::get('/family-details', [UserFamilyDetailsController::class, 'index'])->name('family-details.index');
Route::put('/family-details', [UserFamilyDetailsController::class, 'edit'])->name('family-details.edit');
Route::post('/family-details', [UserFamilyDetailsController::class, 'addFamilyData'])->name('family-details.addFamilyData');
Route::delete('/family-details/{id}', [UserFamilyDetailsController::class, 'destroy'])->name('family-details.destroy');


Route::get('/health-details', [HealthDetailsController::class, 'index'])->name('health-details.index');
Route::post('/health', [HealthDetailsController::class, 'addHealthData'])->name('health-details.addHealthData');
Route::get('/health-details/{id}/edit', 'HealthDetailsController@edit')->name('health-details.edit');
Route::delete('/health-details/{id}', 'HealthDetailsController@delete')->name('health-details.delete');
Route::delete('/health-details/{id}', [HealthDetailsController::class, 'deleteHealthData'])->name('health-details.delete');

Route::get('/ccbrt_relation', [CcbrtRelationController::class, 'index'])->name('ccbrt_relation.index');
Route::delete('/ccbrt_relation/{id}', [CcbrtRelationController::class, 'destroy'])->name('ccbrt_relation.destroy');
Route::post('/relation', [CcbrtRelationController::class, 'addRelationData'])->name('ccbrt_relation.addRelationData');

Route::get('/language-knowledge', [LanguageKnowledgeController::class, 'index'])->name('language_knowledge.index');
Route::post('/language-knowledge', [LanguageKnowledgeController::class, 'addLanguageKnowledge'])->name('language_knowledge.add');

Expand Down

0 comments on commit af45f9f

Please sign in to comment.