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 @@