diff --git a/app/User.php b/app/User.php index 2e5067c..1409f07 100644 --- a/app/User.php +++ b/app/User.php @@ -96,6 +96,16 @@ class User extends Authenticatable return link_to_route('users.'.$type, $this->name, [$this->id]); } + public function fatherLink() + { + return $this->father_id ? link_to_route('users.show', $this->father->name, [$this->father_id]) : null; + } + + public function motherLink() + { + return $this->mother_id ? link_to_route('users.show', $this->mother->name, [$this->mother_id]) : null; + } + public function wifes() { return $this->belongsToMany(User::class, 'couples', 'husband_id', 'wife_id')->withPivot(['id'])->withTimestamps(); diff --git a/resources/views/users/partials/parent-spouse.blade.php b/resources/views/users/partials/parent-spouse.blade.php index f66d32b..974b789 100644 --- a/resources/views/users/partials/parent-spouse.blade.php +++ b/resources/views/users/partials/parent-spouse.blade.php @@ -19,17 +19,13 @@ {{ Form::close() }} @else - @if ($user->father_id) - {{ $user->father->profileLink() }} - @endif + {{ $user->fatherLink() }}
{{ link_to_route('users.show', 'Set Ayah', [$user->id, 'action' => 'set_father'], ['class' => 'btn btn-link btn-xs']) }}
@endif @else - @if ($user->father_id) - {{ $user->father->profileLink() }} - @endif + {{ $user->fatherLink() }} @endcan @@ -39,7 +35,7 @@ @can ('edit', $currentUser) @if (request('action') == 'set_mother') {{ Form::open(['route' => ['family-actions.set-mother', $user->id]]) }} - {!! FormField::select('set_mother_id', $femalePersonList, ['label' => false, 'value' => $user->mother_id, 'placeholder' => 'Pilih dari Laki-laki Terdaftar']) !!} + {!! FormField::select('set_mother_id', $femalePersonList, ['label' => false, 'value' => $user->mother_id, 'placeholder' => 'Pilih dari Wanita Terdaftar']) !!}
{{ Form::text('set_mother', null, ['class' => 'form-control input-sm', 'placeholder' => 'Input Nama Baru...']) }} @@ -49,17 +45,13 @@
{{ Form::close() }} @else - @if ($user->mother_id) - {{ $user->mother->profileLink() }} - @endif + {{ $user->motherLink() }}
{{ link_to_route('users.show', 'Set Ibu', [$user->id, 'action' => 'set_mother'], ['class' => 'btn btn-link btn-xs']) }}
@endif @else - @if ($user->mother_id) - {{ $user->mother->profileLink() }} - @endif + {{ $user->motherLink() }} @endcan diff --git a/tests/Unit/UserTest.php b/tests/Unit/UserTest.php index 8e9c032..b2b19d7 100644 --- a/tests/Unit/UserTest.php +++ b/tests/Unit/UserTest.php @@ -28,4 +28,22 @@ class UserTest extends TestCase $this->assertCount(1, $wife->husbands); $this->assertCount(1, $husband->marriages); } + + /** @test */ + public function user_have_father_link_method() + { + $father = factory(User::class)->create(); + $user = factory(User::class)->create(['father_id' => $father->id]); + + $this->assertEquals($father->profileLink(), $user->fatherLink()); + } + + /** @test */ + public function user_have_mother_link_method() + { + $mother = factory(User::class)->create(); + $user = factory(User::class)->create(['mother_id' => $mother->id]); + + $this->assertEquals($mother->profileLink(), $user->motherLink()); + } }