diff --git a/CHANGELOG b/CHANGELOG index f513eb2b3ee..2d8bbc893aa 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -10,6 +10,7 @@ Enhancements: Fixes: +* Fix display relationship without a ofContact property * Fix register request validate * Fix relationship create diff --git a/app/Http/Controllers/Contacts/RelationshipsController.php b/app/Http/Controllers/Contacts/RelationshipsController.php index b0c99e84c50..fee267c29ad 100644 --- a/app/Http/Controllers/Contacts/RelationshipsController.php +++ b/app/Http/Controllers/Contacts/RelationshipsController.php @@ -105,12 +105,14 @@ public function store(Request $request, Contact $contact) * Show the form for editing the specified resource. * * @param Contact $contact - * @param Contact $otherContact significant other contact + * @param Relationship $relationship * * @return \Illuminate\View\View */ - public function edit(Contact $contact, Contact $otherContact) + public function edit(Contact $contact, Relationship $relationship) { + $otherContact = $relationship->ofContact; + $now = now(); $age = (string) (! is_null($otherContact->birthdate) ? $otherContact->birthdate->getAge() : 0); $birthdate = ! is_null($otherContact->birthdate) ? $otherContact->birthdate->date->toDateString() : $now->toDateString(); @@ -119,9 +121,6 @@ public function edit(Contact $contact, Contact $otherContact) $hasBirthdayReminder = is_null($otherContact->birthday_reminder_id) ? 0 : 1; - // Get the nature of the current relationship - $type = $contact->getRelationshipNatureWith($otherContact); - return view('people.relationship.edit') ->withContact($contact) ->withPartner($otherContact) @@ -130,14 +129,14 @@ public function edit(Contact $contact, Contact $otherContact) ->withDays(DateHelper::getListOfDays()) ->withMonths(DateHelper::getListOfMonths()) ->withBirthdate($birthdate) - ->withType($type->relationship_type_id) + ->withRelationshipId($relationship->id) + ->withType($relationship->relationship_type_id) ->withBirthdayState($otherContact->getBirthdayState()) ->withDay($day) ->withMonth($month) ->withAge($age) ->withGenders(GendersHelper::getGendersInput()) - ->withHasBirthdayReminder($hasBirthdayReminder) - ->withRelationshipId($type->id); + ->withHasBirthdayReminder($hasBirthdayReminder); } /** @@ -145,12 +144,14 @@ public function edit(Contact $contact, Contact $otherContact) * * @param Request $request * @param Contact $contact - * @param Contact $otherContact significant other contact + * @param Relationship $relationship * * @return \Illuminate\Http\RedirectResponse */ - public function update(Request $request, Contact $contact, Contact $otherContact) + public function update(Request $request, Contact $contact, Relationship $relationship) { + $otherContact = $relationship->ofContact; + if ($otherContact->is_partial) { $datas = $this->validateAndGetDatas($request); @@ -168,7 +169,7 @@ public function update(Request $request, Contact $contact, Contact $otherContact // update the relationship app(UpdateRelationship::class)->execute([ 'account_id' => auth()->user()->account_id, - 'relationship_id' => $request->get('relationship_id'), + 'relationship_id' => $relationship->id, 'relationship_type_id' => $request->get('relationship_type_id'), ]); @@ -230,22 +231,20 @@ private function validateAndGetDatas(Request $request) * Remove the specified resource from storage. * * @param Contact $contact - * @param Contact $otherContact + * @param Relationship $relationship * * @return \Illuminate\Http\RedirectResponse */ - public function destroy(Contact $contact, Contact $otherContact) + public function destroy(Contact $contact, Relationship $relationship) { if ($contact->account_id != auth()->user()->account_id) { return redirect()->route('people.index'); } - if ($otherContact->account_id != auth()->user()->account_id) { + if ($relationship->account_id != auth()->user()->account_id) { return redirect()->route('people.index'); } - $relationship = $contact->getRelationshipNatureWith($otherContact); - app(DestroyRelationship::class)->execute([ 'account_id' => auth()->user()->account_id, 'relationship_id' => $relationship->id, diff --git a/app/Models/Contact/Contact.php b/app/Models/Contact/Contact.php index f5f2ac281c1..cfc1dd8d947 100644 --- a/app/Models/Contact/Contact.php +++ b/app/Models/Contact/Contact.php @@ -1300,22 +1300,6 @@ public function setSpecialDateFromAge($occasion, int $age) return $specialDate; } - /** - * Get the Relationship object representing the relation between two contacts. - * - * @param Contact $otherContact - * @return Relationship|null - */ - public function getRelationshipNatureWith(self $otherContact) - { - return Relationship::where([ - 'account_id' => $this->account_id, - 'contact_is' => $this->id, - 'of_contact' => $otherContact->id, - ]) - ->first(); - } - /** * Delete all related objects. * diff --git a/app/Models/Relationship/Relationship.php b/app/Models/Relationship/Relationship.php index ba1f119e143..df8e215a05b 100644 --- a/app/Models/Relationship/Relationship.php +++ b/app/Models/Relationship/Relationship.php @@ -4,7 +4,7 @@ use App\Models\Account\Account; use App\Models\Contact\Contact; -use Illuminate\Database\Eloquent\Model; +use App\Models\ModelBinding as Model; use Illuminate\Database\Eloquent\Relations\BelongsTo; /** diff --git a/resources/views/people/relationship/_relationship.blade.php b/resources/views/people/relationship/_relationship.blade.php index 96e03bd20f9..884991d0bfe 100644 --- a/resources/views/people/relationship/_relationship.blade.php +++ b/resources/views/people/relationship/_relationship.blade.php @@ -1,4 +1,7 @@ @foreach ($relationships as $relationship) + @if (! $relationship->ofContact) + @continue + @endif