Skip to content

Commit

Permalink
Merge pull request sebastianbergmann#87 from sheby460/chumaBranch
Browse files Browse the repository at this point in the history
Chuma branch
  • Loading branch information
sheby460 authored Jul 17, 2024
2 parents 1e42e07 + 54e6f88 commit 6ecf0c1
Show file tree
Hide file tree
Showing 5 changed files with 336 additions and 129 deletions.
95 changes: 77 additions & 18 deletions app/Http/Controllers/HealthDetailsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -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'));
}
Expand All @@ -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
]);
}

}
22 changes: 11 additions & 11 deletions app/Http/Controllers/UserFamilyDetailsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(), [
Expand Down
Loading

0 comments on commit 6ecf0c1

Please sign in to comment.