Browse Source

Add marriage date on add husband action

pull/8/head
Nafies Luthfi 8 years ago
parent
commit
187ad327a5
  1. 3
      app/Http/Controllers/FamilyActionsController.php
  2. 4
      app/User.php
  3. 15
      resources/views/users/partials/parent-spouse.blade.php
  4. 4
      tests/Feature/ManageUserFamiliesTest.php

3
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();
}

4
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;
}

15
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
</div>
@endcan
@ -151,12 +151,17 @@
<div>
{{ Form::open(['route' => ['family-actions.add-husband', $user->id]]) }}
{!! FormField::select('set_husband_id', $malePersonList, ['label' => false, 'placeholder' => trans('app.select_from_existing_males')]) !!}
<div class="input-group">
<div class="form-group">
<div class="row">
<div class="col-md-7">
{{ Form::text('set_husband', null, ['class' => 'form-control input-sm', 'placeholder' => trans('app.enter_new_name')]) }}
<span class="input-group-btn">
{{ Form::submit('update', ['class' => 'btn btn-info btn-sm', 'id' => 'set_husband_button']) }}
</span>
</div>
<div class="col-md-5">
{{ Form::text('marriage_date', null, ['class' => 'form-control input-sm', 'placeholder' => trans('couple.marriage_date')]) }}
</div>
</div>
</div>
{{ Form::submit('update', ['class' => 'btn btn-info btn-sm', 'id' => 'set_husband_button']) }}
{{ Form::close() }}
</div>
@endif

4
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',
]);
}

Loading…
Cancel
Save