diff --git a/app/Http/Controllers/HealthDetailsController.php b/app/Http/Controllers/HealthDetailsController.php index 6c14d56..73df8eb 100644 --- a/app/Http/Controllers/HealthDetailsController.php +++ b/app/Http/Controllers/HealthDetailsController.php @@ -3,10 +3,11 @@ namespace App\Http\Controllers; use Illuminate\Http\Request; -use App\Models\User; -use App\Models\HealthDetails; 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 { @@ -18,10 +19,7 @@ class HealthDetailsController extends Controller public function index() { $user = Auth::user(); - $healthDetails = HealthDetails::with('user')->get(); - - // Fetch the authenticated user's data with profile picture - $user = User::find($user->id); + $healthDetails = HealthDetails::where('userId', $user->id)->get(); return view('health-details.index', compact('healthDetails', 'user')); } @@ -34,21 +32,82 @@ public function index() */ public function addHealthData(Request $request) { - $request->validate([ + $validator = Validator::make($request->all(), [ 'userId' => 'required|exists:users,id', - 'physical_disability' => 'nullable|string|max:255', - 'blood_group' => 'nullable|string|max:10', - 'illness_history' => 'nullable|string', - 'health_insurance' => 'nullable|string|max:255', - 'insur_name' => 'nullable|string|max:255', - 'insur_no' => 'nullable|string|max:50', - 'allergies' => 'nullable|string', - 'delete_status' => 'nullable|boolean', + 'physical_disability' => 'required', + 'health_insurance' => 'required', + ]); - $healthDetail = HealthDetails::create($request->all()); + if ($validator->fails()) { + return response()->json([ + 'status' => 400, + 'error' => $validator->errors() + ]); + } + + HealthDetails::create([ + 'userId' => $request->input('userId'), + 'physical_disability' => $request->input('physical_disability'), + 'blood_group' => $request->input('blood_group'), + 'illness_history' => $request->input('illness_history'), + 'health_insurance' => $request->input('health_insurance'), + 'insur_name' => $request->input('insur_name'), + 'insur_no' => $request->input('insur_no'), + 'allergies' => $request->input('allergies'), + 'delete_status' =>0, + ]); - return redirect()->route('health-details.index') - ->with('success', 'Health detail added successfully.'); + return redirect()->route('health-details.index')->with('success', 'Health details added successfully.'); } + + public function edit(string $id){ + $healthData = HealthDetails::findOrFail($id); + return view('health-details.edit', compact('healthData')); + } + + public function updateHealthDetails(Request $request, string $id){ + + $validator = Validator::make($request->all(),[ + 'physical_disability' => 'required', + 'health_insurance' => 'required', + ]); + + if ($validator->fails()) { + return response()->json([ + 'status' => 400, + 'errors' => $validator->errors(), + ]); + } + + $healthData = HealthDetails::findOrFail($id); + $healthData->update([ + 'physical_disability' => $request->input('physical_disability'), + 'blood_group' => $request->input('blood_group'), + 'illness_history' => $request->input('illness_history'), + 'health_insurance' => $request->input('health_insurance'), + 'insur_name' => $request->input('insur_name'), + 'insur_no' => $request->input('insur_no'), + 'allergies' => $request->input('allergies'), + ]); + Alert::success('Health detail Updated successful','Health details updated'); + return redirect()->route('health-details.index')->with('success', 'Department updated successfully.'); + + } + + public function deleteHealthData(string $id){ + $health = HealthDetails::find($id); + + if(!$health){ + return response()->json([ + 'status' => 400, + 'massage' => ' Health detail not found', + ]); + } + + $health->update([ + 'delete_status' => 1 + ]); + } + } diff --git a/app/Http/Controllers/UserFamilyDetailsController.php b/app/Http/Controllers/UserFamilyDetailsController.php index 695cdc7..6e7682c 100644 --- a/app/Http/Controllers/UserFamilyDetailsController.php +++ b/app/Http/Controllers/UserFamilyDetailsController.php @@ -16,36 +16,36 @@ public function index() return view('family-details.index', compact('user', 'familyData')); } - public function addFamilyData(Request $request) { $validator = Validator::make($request->all(), [ - 'userId' => 'required|exists:users,id', 'familyData.*.full_name' => 'required|string|max:255', 'familyData.*.relationship' => 'required|string|max:255', - 'familyData.*.phone_number' => 'required|string|max:15', + 'familyData.*.phone_number' => 'nullable|string|max:15', 'familyData.*.occupation' => 'nullable|string|max:255', + 'familyData.*.DOB' => 'nullable|date', ]); - + if ($validator->fails()) { return redirect()->back()->withErrors($validator)->withInput(); } - $userId =Auth::user(); - //dd($userId); + + $userId = Auth::id(); // Get authenticated user's ID + foreach ($request->familyData as $data) { UserFamilyDetails::create([ - 'userId' => $userId , + 'userId' => $userId, 'full_name' => $data['full_name'], 'relationship' => $data['relationship'], 'phone_number' => $data['phone_number'], - 'DOB' => $data['DOB'], 'occupation' => $data['occupation'], + 'DOB' => $data['DOB'], ]); } - - return redirect()->route('profile.show')->with('success', 'Family details added successfully.'); + + return redirect()->route('family-details.index')->with('success', 'Family details added successfully.'); } - + public function addHealthData(Request $request) { $validator = Validator::make($request->all(), [ diff --git a/resources/views/health-details/create.blade.php b/resources/views/health-details/create.blade.php index 5237e0f..236a27e 100644 --- a/resources/views/health-details/create.blade.php +++ b/resources/views/health-details/create.blade.php @@ -1,80 +1,234 @@ -
- @csrf - -
- -
-
- - -
-
- - -
-
-
-
- - -
-
- - -
-
-
-
- - -
-
-
-
-
- -
-
- - -
-
- - -
-
-
-
- - -
-
- - -
-
-
-
- - + + + +@extends('layouts.template') + +@section('breadcrumb') + @include('sweetalert::alert') + +
+
+ -
-
-
-
-
- - + + +
+
+
+
+
+
+
+
+
+
+
+
+ Profile Picture + + @csrf + + +
+
+
+
+
+

{{ $user->username }}

+

{{ $user->email }}

+

{{ $user->department->name }}

+
+ +
+
+
+
Joined 09 July 2024
+
+
+ +
+
+ + +
+
+ +
+
+ @csrf +
+
+
+ + + @error('physical_disability') + + {{ $message }} + + @enderror +
+
+ + +
+
+ + +
+
+
+
+ + + +
+
+ + + +
+
+ + + +
+
+ + + +
+
+
+ +
+
+ +
+
+
+ +
+

Health Details

+ + + + + + + + + + + + + + + + @foreach ($healthDetails as $health) + + + + + + + + + + + @endforeach + +
Physical DisabilityBlood GroupIllness HistoryHealth InsuranceInsurance NameInsurance NumberAllergiesAction
{{ $health->physical_disability }}{{ $health->blood_group }}{{ $health->illness_history }}{{ $health->health_insurance }}{{ $health->insur_name }}{{ $health->insur_no }}{{ $health->allergies }} + Edit +
+ @csrf + @method('DELETE') + +
+
+
+
+ + + +
+ +
+
+
+
+ +
+
+
-
-
- -
-
- \ No newline at end of file +@endsection diff --git a/resources/views/health-details/index.blade.php b/resources/views/health-details/index.blade.php index 9843f97..932a978 100644 --- a/resources/views/health-details/index.blade.php +++ b/resources/views/health-details/index.blade.php @@ -1,5 +1,3 @@ - - @extends('layouts.template') @section('breadcrumb') @@ -74,29 +72,18 @@ function handleProfilePictureChange(input) {
-
+
@csrf +
@@ -142,7 +129,8 @@ class="nav-link">Language
- +
@@ -168,7 +156,8 @@ class="nav-link">Language
- +
@@ -227,9 +216,6 @@ class="btn btn-sm btn-danger"
- - -
diff --git a/routes/web.php b/routes/web.php index a8a9504..b3f2172 100644 --- a/routes/web.php +++ b/routes/web.php @@ -70,15 +70,23 @@ -Route::get('/family-details', [UserFamilyDetailsController::class, 'index'])->name('family-details.index'); + Route::get('/family-details', [UserFamilyDetailsController::class, 'index'])->name('family-details.index'); Route::post('/familyData', [UserFamilyDetailsController::class, 'addFamilyData'])->name('family-details.addFamilyData'); + + 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::get('/relation-details', [CcbrtRelationController::class, 'index'])->name('relation-details.index'); Route::post('/relation', [CcbrtRelationController::class, 'addRelationData'])->name('relation-details.addRelationData'); Route::get('/language-knowledge', [LanguageKnowledgeController::class, 'index'])->name('language_knowledge.index'); Route::post('/language-knowledge', [LanguageKnowledgeController::class, 'addLanguageKnowledge'])->name('language_knowledge.add'); + // Route::post('family-details', UserFamilyDetailsController::class); // Route::post('/healthDetails', [UserFamilyDetailsController::class, 'addHealthData'])->name('healthDetails.addHealthData'); // Route::post('/languageData', [UserFamilyDetailsController::class, 'addLanguage'])->name('languageData.addLanguage');