Browse Source

Move family_member_connections entry to controller

family_member_connections
Nafies Luthfi 5 years ago
parent
commit
3912055b37
  1. 36
      app/Http/Controllers/FamilyActionsController.php
  2. 25
      app/User.php

36
app/Http/Controllers/FamilyActionsController.php

@ -42,6 +42,12 @@ class FamilyActionsController extends Controller
$father->manager_id = auth()->id(); $father->manager_id = auth()->id();
$user->setFather($father); $user->setFather($father);
DB::table('family_member_connections')->insert([
'id' => Uuid::uuid4()->toString(),
'requester_id' => $user->id,
'requested_id' => $father->id,
]);
} }
return back(); return back();
@ -79,6 +85,12 @@ class FamilyActionsController extends Controller
$mother->manager_id = auth()->id(); $mother->manager_id = auth()->id();
$user->setMother($mother); $user->setMother($mother);
DB::table('family_member_connections')->insert([
'id' => Uuid::uuid4()->toString(),
'requester_id' => $user->id,
'requested_id' => $mother->id,
]);
} }
return back(); return back();
@ -120,8 +132,20 @@ class FamilyActionsController extends Controller
} else { } else {
if ($user->gender_id == 1) { if ($user->gender_id == 1) {
$child->setFather($user); $child->setFather($user);
DB::table('family_member_connections')->insert([
'id' => Uuid::uuid4()->toString(),
'requester_id' => $child->id,
'requested_id' => $user->id,
]);
} else { } else {
$child->setMother($user); $child->setMother($user);
DB::table('family_member_connections')->insert([
'id' => Uuid::uuid4()->toString(),
'requester_id' => $child->id,
'requested_id' => $user->id,
]);
} }
} }
@ -159,6 +183,12 @@ class FamilyActionsController extends Controller
$user->addWife($wife, $request->get('marriage_date')); $user->addWife($wife, $request->get('marriage_date'));
DB::table('family_member_connections')->insert([
'id' => Uuid::uuid4()->toString(),
'requester_id' => $user->id,
'requested_id' => $wife->id,
]);
return back(); return back();
} }
@ -190,6 +220,12 @@ class FamilyActionsController extends Controller
$user->addHusband($husband, $request->get('marriage_date')); $user->addHusband($husband, $request->get('marriage_date'));
DB::table('family_member_connections')->insert([
'id' => Uuid::uuid4()->toString(),
'requester_id' => $user->id,
'requested_id' => $husband->id,
]);
return back(); return back();
} }

25
app/User.php

@ -5,7 +5,6 @@ namespace App;
use Carbon\Carbon; use Carbon\Carbon;
use Illuminate\Foundation\Auth\User as Authenticatable; use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable; use Illuminate\Notifications\Notifiable;
use Illuminate\Support\Facades\DB;
use Ramsey\Uuid\Uuid; use Ramsey\Uuid\Uuid;
class User extends Authenticatable class User extends Authenticatable
@ -77,12 +76,6 @@ class User extends Authenticatable
$this->father_id = $father->id; $this->father_id = $father->id;
$this->save(); $this->save();
DB::table('family_member_connections')->insert([
'id' => Uuid::uuid4()->toString(),
'requester_id' => $this->id,
'requested_id' => $father->id,
]);
return $father; return $father;
} }
@ -100,12 +93,6 @@ class User extends Authenticatable
$this->mother_id = $mother->id; $this->mother_id = $mother->id;
$this->save(); $this->save();
DB::table('family_member_connections')->insert([
'id' => Uuid::uuid4()->toString(),
'requester_id' => $this->id,
'requested_id' => $mother->id,
]);
return $mother; return $mother;
} }
@ -161,12 +148,6 @@ class User extends Authenticatable
'manager_id' => auth()->id(), 'manager_id' => auth()->id(),
]); ]);
DB::table('family_member_connections')->insert([
'id' => Uuid::uuid4()->toString(),
'requester_id' => $this->id,
'requested_id' => $wife->id,
]);
return $wife; return $wife;
} }
@ -187,12 +168,6 @@ class User extends Authenticatable
'manager_id' => auth()->id(), 'manager_id' => auth()->id(),
]); ]);
DB::table('family_member_connections')->insert([
'id' => Uuid::uuid4()->toString(),
'requester_id' => $this->id,
'requested_id' => $husband->id,
]);
return $husband; return $husband;
} }

Loading…
Cancel
Save