feat: add ability to favorite contacts (#1691)

This commit is contained in:
Régis Freyd
2018-08-16 18:03:02 -04:00
committed by Alexis Saettler
parent 5aa3afa08a
commit 1d35dea8b8
20 changed files with 288 additions and 78 deletions
@@ -70,8 +70,19 @@ class ContactsController extends Controller
$contacts = $user->account->contacts()->real()->sortedBy($sort)->get();
}
// starred contacts
$starredContacts = $contacts->filter(function ($item) {
return $item->is_starred === true;
});
$unstarredContacts = $contacts->filter(function ($item) {
return $item->is_starred === false;
});
return view('people.index')
->withContacts($contacts->unique('id'))
->withUnstarredContacts($unstarredContacts)
->withStarredContacts($starredContacts)
->withTags($tags)
->withUserTags(auth()->user()->account->tags)
->withUrl($url)
@@ -499,4 +510,22 @@ class ContactsController extends Controller
return $frequency;
}
/**
* Toggle favorites of a contact.
* @param Request $request
* @param Contact $contact
* @return array
*/
public function favorite(Request $request, Contact $contact)
{
$bool = (bool) $request->get('toggle');
$contact->is_starred = $bool;
$contact->save();
return [
'is_starred' => $bool,
];
}
}