built user profile added the logo created the family view etc
This commit is contained in:
1 parent
4a7353e3fc
commit
43c2676d6f
33 files changed
+3783
-257
No files matched your search
@@ -5,6 +5,8 @@ namespace App\Services;
|
||||
use App\Models\User;
|
||||
use App\Models\UserRelationship;
|
||||
use App\Models\Invoice;
|
||||
use App\Mail\WelcomeEmail;
|
||||
use Illuminate\Support\Facades\Mail;
|
||||
|
||||
class FamilyService
|
||||
{
|
||||
@@ -17,15 +19,24 @@ class FamilyService
|
||||
*/
|
||||
public function createDependent(User $guardian, array $data): User
|
||||
{
|
||||
// Normalize gender value to match database enum (m/f)
|
||||
$gender = $data['gender'];
|
||||
if ($gender === 'male') {
|
||||
$gender = 'm';
|
||||
} elseif ($gender === 'female') {
|
||||
$gender = 'f';
|
||||
}
|
||||
|
||||
// Create the dependent user
|
||||
$dependent = User::create([
|
||||
'name' => $data['full_name'], // Required by database
|
||||
'full_name' => $data['full_name'],
|
||||
'email' => $data['email'] ?? null,
|
||||
'password' => $data['password'] ?? null,
|
||||
'mobile' => $data['mobile'] ?? null,
|
||||
'gender' => $data['gender'],
|
||||
'gender' => $gender,
|
||||
'birthdate' => $data['birthdate'],
|
||||
'blood_type' => $data['blood_type'] ?? null,
|
||||
'blood_type' => $data['blood_type'] ?? 'Unknown',
|
||||
'nationality' => $data['nationality'],
|
||||
'addresses' => $data['addresses'] ?? [],
|
||||
'social_links' => $data['social_links'] ?? [],
|
||||
@@ -33,13 +44,18 @@ class FamilyService
|
||||
]);
|
||||
|
||||
// Create the relationship between guardian and dependent
|
||||
UserRelationship::create([
|
||||
$relationship = UserRelationship::create([
|
||||
'guardian_user_id' => $guardian->id,
|
||||
'dependent_user_id' => $dependent->id,
|
||||
'relationship_type' => $data['relationship_type'],
|
||||
'is_billing_contact' => $data['is_billing_contact'] ?? false,
|
||||
]);
|
||||
|
||||
// Send welcome email if dependent has an email address
|
||||
if (!empty($dependent->email)) {
|
||||
Mail::to($dependent->email)->send(new WelcomeEmail($dependent, $guardian, $relationship));
|
||||
}
|
||||
|
||||
return $dependent;
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user