From fb3c214077c0e7aeced51feb46e0ced516addf59 Mon Sep 17 00:00:00 2001 From: Nafies Luthfi Date: Wed, 28 Jun 2017 17:56:45 +0800 Subject: [PATCH] Update proper siblings query and added person gender on chart page --- app/User.php | 25 ++++++++++++++----------- resources/views/users/chart.blade.php | 12 ++++++------ 2 files changed, 20 insertions(+), 17 deletions(-) diff --git a/app/User.php b/app/User.php index 7d66629..991f8ab 100644 --- a/app/User.php +++ b/app/User.php @@ -37,7 +37,7 @@ class User extends Authenticatable public function getGenderAttribute() { - return $this->gender_id == 1 ? 'Laki-laki' : 'Perempuan'; + return $this->gender_id == 1 ? 'L' : 'P'; } public function setFather(User $father) @@ -136,16 +136,19 @@ class User extends Authenticatable public function siblings() { - // TODO: research for fit siblings query - return User::where(function ($query) { - $query->where('id', '!=', $this->id); - if ($this->father_id != null) - $query->where('father_id', $this->father_id); - // if ($this->mother_id != null) - // $query->where('mother_id', $this->mother_id); - // if ($this->parent_id != null) - // $query->where('parent_id', $this->parent_id); - })->get(); + if (is_null($this->father_id) && is_null($this->mother_id) && is_null($this->parent_id)) + return collect([]); + + return User::where('id', '!=', $this->id) + ->where(function ($query) { + if (!is_null($this->father_id)) + $query->where('father_id', $this->father_id); + if (!is_null($this->mother_id)) + $query->orWhere('mother_id', $this->mother_id); + if (!is_null($this->parent_id)) + $query->orWhere('parent_id', $this->parent_id); + }) + ->get(); } public function parent() diff --git a/resources/views/users/chart.blade.php b/resources/views/users/chart.blade.php index e21c7b6..3376a0c 100644 --- a/resources/views/users/chart.blade.php +++ b/resources/views/users/chart.blade.php @@ -30,16 +30,16 @@   - {{ $user->profileLink('chart') }} + {{ $user->profileLink('chart') }} ({{ $user->gender }}) Anak-Anak & Cucu-Cucu @foreach($childs as $child) - {{ $child->profileLink('chart') }} + {{ $child->profileLink('chart') }} ({{ $child->gender }}) @@ -57,7 +57,7 @@ Saudara - {{ $sibling->profileLink('chart') }} + {{ $sibling->profileLink('chart') }} ({{ $sibling->gender }}) Keponakan & Cucu-Cucu @@ -65,10 +65,10 @@
    @foreach($sibling->childs as $child)
  1. - {{ $child->profileLink('chart') }} + {{ $child->profileLink('chart') }} ({{ $child->gender }})
      @foreach($child->childs as $grand) -
    • {{ $grand->profileLink('chart') }}
    • +
    • {{ $grand->profileLink('chart') }} ({{ $grand->gender }})
    • @endforeach