From 3912055b37cba7d0aa16170cf55897f1bf67b2fa Mon Sep 17 00:00:00 2001 From: Nafies Luthfi Date: Sun, 28 Mar 2021 12:00:49 +0800 Subject: [PATCH] Move family_member_connections entry to controller --- app/Http/Controllers/FamilyActionsController.php | 36 ++++++++++++++++++++++++ app/User.php | 25 ---------------- 2 files changed, 36 insertions(+), 25 deletions(-) diff --git a/app/Http/Controllers/FamilyActionsController.php b/app/Http/Controllers/FamilyActionsController.php index 47277ae..d59db6d 100644 --- a/app/Http/Controllers/FamilyActionsController.php +++ b/app/Http/Controllers/FamilyActionsController.php @@ -42,6 +42,12 @@ class FamilyActionsController extends Controller $father->manager_id = auth()->id(); $user->setFather($father); + + DB::table('family_member_connections')->insert([ + 'id' => Uuid::uuid4()->toString(), + 'requester_id' => $user->id, + 'requested_id' => $father->id, + ]); } return back(); @@ -79,6 +85,12 @@ class FamilyActionsController extends Controller $mother->manager_id = auth()->id(); $user->setMother($mother); + + DB::table('family_member_connections')->insert([ + 'id' => Uuid::uuid4()->toString(), + 'requester_id' => $user->id, + 'requested_id' => $mother->id, + ]); } return back(); @@ -120,8 +132,20 @@ class FamilyActionsController extends Controller } else { if ($user->gender_id == 1) { $child->setFather($user); + + DB::table('family_member_connections')->insert([ + 'id' => Uuid::uuid4()->toString(), + 'requester_id' => $child->id, + 'requested_id' => $user->id, + ]); } else { $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')); + DB::table('family_member_connections')->insert([ + 'id' => Uuid::uuid4()->toString(), + 'requester_id' => $user->id, + 'requested_id' => $wife->id, + ]); + return back(); } @@ -190,6 +220,12 @@ class FamilyActionsController extends Controller $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(); } diff --git a/app/User.php b/app/User.php index a069885..3ce5271 100644 --- a/app/User.php +++ b/app/User.php @@ -5,7 +5,6 @@ namespace App; use Carbon\Carbon; use Illuminate\Foundation\Auth\User as Authenticatable; use Illuminate\Notifications\Notifiable; -use Illuminate\Support\Facades\DB; use Ramsey\Uuid\Uuid; class User extends Authenticatable @@ -77,12 +76,6 @@ class User extends Authenticatable $this->father_id = $father->id; $this->save(); - DB::table('family_member_connections')->insert([ - 'id' => Uuid::uuid4()->toString(), - 'requester_id' => $this->id, - 'requested_id' => $father->id, - ]); - return $father; } @@ -100,12 +93,6 @@ class User extends Authenticatable $this->mother_id = $mother->id; $this->save(); - DB::table('family_member_connections')->insert([ - 'id' => Uuid::uuid4()->toString(), - 'requester_id' => $this->id, - 'requested_id' => $mother->id, - ]); - return $mother; } @@ -161,12 +148,6 @@ class User extends Authenticatable 'manager_id' => auth()->id(), ]); - DB::table('family_member_connections')->insert([ - 'id' => Uuid::uuid4()->toString(), - 'requester_id' => $this->id, - 'requested_id' => $wife->id, - ]); - return $wife; } @@ -187,12 +168,6 @@ class User extends Authenticatable 'manager_id' => auth()->id(), ]); - DB::table('family_member_connections')->insert([ - 'id' => Uuid::uuid4()->toString(), - 'requester_id' => $this->id, - 'requested_id' => $husband->id, - ]); - return $husband; }