From 187ad327a55490d9d74fbd20b0c544f713af420f Mon Sep 17 00:00:00 2001 From: Nafies Luthfi Date: Wed, 28 Feb 2018 07:23:21 +0800 Subject: [PATCH] Add marriage date on add husband action --- app/Http/Controllers/FamilyActionsController.php | 3 ++- app/User.php | 4 ++-- resources/views/users/partials/parent-spouse.blade.php | 17 +++++++++++------ tests/Feature/ManageUserFamiliesTest.php | 4 ++++ 4 files changed, 19 insertions(+), 9 deletions(-) diff --git a/app/Http/Controllers/FamilyActionsController.php b/app/Http/Controllers/FamilyActionsController.php index 1856adf..1e1dce5 100644 --- a/app/Http/Controllers/FamilyActionsController.php +++ b/app/Http/Controllers/FamilyActionsController.php @@ -117,6 +117,7 @@ class FamilyActionsController extends Controller $this->validate($request, [ 'set_husband_id' => 'nullable', 'set_husband' => 'required_without:set_husband_id|max:255', + 'marriage_date' => 'nullable|date|date_format:Y-m-d', ]); if ($request->get('set_husband_id')) { @@ -129,7 +130,7 @@ class FamilyActionsController extends Controller $husband->manager_id = auth()->id(); } - $user->addHusband($husband); + $user->addHusband($husband, $request->get('marriage_date')); return back(); } diff --git a/app/User.php b/app/User.php index 9c141a0..362ca85 100644 --- a/app/User.php +++ b/app/User.php @@ -126,10 +126,10 @@ class User extends Authenticatable return $this->belongsToMany(User::class, 'couples', 'wife_id', 'husband_id')->withPivot(['id'])->withTimestamps(); } - public function addHusband(User $husband) + public function addHusband(User $husband, $marriageDate = null) { if ($this->gender_id == 2 && ! $this->hasBeenMarriedTo($husband)) { - $this->husbands()->save($husband); + $this->husbands()->save($husband, ['marriage_date' => $marriageDate]); return $husband; } diff --git a/resources/views/users/partials/parent-spouse.blade.php b/resources/views/users/partials/parent-spouse.blade.php index 65b8b2d..afc9e49 100644 --- a/resources/views/users/partials/parent-spouse.blade.php +++ b/resources/views/users/partials/parent-spouse.blade.php @@ -135,7 +135,7 @@ @if (request('action') == 'add_spouse') {{ link_to_route('users.show', trans('app.cancel'), [$user->id], ['class' => 'btn btn-default btn-xs']) }} @else - {{ link_to_route('users.show', trans('user.add_husband'), [$user->id, 'action' => 'add_spouse'], ['class' => 'btn btn-success btn-xs']) }} + {{ link_to_route('users.show', trans('user.add_husband'), [$user->id, 'action' => 'add_spouse'], ['class' => 'btn btn-link btn-xs']) }} @endif @endcan @@ -151,12 +151,17 @@
{{ Form::open(['route' => ['family-actions.add-husband', $user->id]]) }} {!! FormField::select('set_husband_id', $malePersonList, ['label' => false, 'placeholder' => trans('app.select_from_existing_males')]) !!} -
- {{ Form::text('set_husband', null, ['class' => 'form-control input-sm', 'placeholder' => trans('app.enter_new_name')]) }} - - {{ Form::submit('update', ['class' => 'btn btn-info btn-sm', 'id' => 'set_husband_button']) }} - +
+
+
+ {{ Form::text('set_husband', null, ['class' => 'form-control input-sm', 'placeholder' => trans('app.enter_new_name')]) }} +
+
+ {{ Form::text('marriage_date', null, ['class' => 'form-control input-sm', 'placeholder' => trans('couple.marriage_date')]) }} +
+
+ {{ Form::submit('update', ['class' => 'btn btn-info btn-sm', 'id' => 'set_husband_button']) }} {{ Form::close() }}
@endif diff --git a/tests/Feature/ManageUserFamiliesTest.php b/tests/Feature/ManageUserFamiliesTest.php index e2a2acf..6d4db9a 100644 --- a/tests/Feature/ManageUserFamiliesTest.php +++ b/tests/Feature/ManageUserFamiliesTest.php @@ -153,6 +153,7 @@ class ManageUserFamiliesTest extends TestCase $this->submitForm('set_husband_button', [ 'set_husband' => 'Nama Suami', + 'marriage_date' => '2010-03-03', ]); $this->seeInDatabase('users', [ @@ -166,6 +167,7 @@ class ManageUserFamiliesTest extends TestCase $this->seeInDatabase('couples', [ 'husband_id' => $husband->id, 'wife_id' => $user->id, + 'marriage_date' => '2010-03-03', ]); } @@ -253,11 +255,13 @@ class ManageUserFamiliesTest extends TestCase $this->submitForm('set_husband_button', [ 'set_husband' => '', 'set_husband_id' => $husband->id, + 'marriage_date' => '2010-03-03', ]); $this->seeInDatabase('couples', [ 'husband_id' => $husband->id, 'wife_id' => $user->id, + 'marriage_date' => '2010-03-03', ]); }