Skip to content

Instantly share code, notes, and snippets.

@djaiss
Created January 20, 2020 02:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save djaiss/cef7e730182a8b787c20a4a1c3f56f14 to your computer and use it in GitHub Desktop.
Save djaiss/cef7e730182a8b787c20a4a1c3f56f14 to your computer and use it in GitHub Desktop.
ContactController
/**
* Display a listing of the resource.
*
* @param Request $request
*
* @return \Illuminate\View\View|\Illuminate\Http\RedirectResponse
*/
public function index(Request $request)
{
$user = auth()->user();
$allContacts = $user->account->contacts()->real();
$numberArchivedContacts = $allContacts->count() - $allContacts->active()->count();
$tags = $user->account->tags()->with('contacts')->orderBy('name')->get();
$contactsCollection = collect([]);
foreach ($allContacts->paginate(30) as $contact) {
//filter out archived contacts
if ($contact->is_active) {
$contactItem = [
'id' => $contact->id,
'name' => $contact->name,
'route' => route('people.show', $contact),
'avatar' => $contact->getAvatarUrl(),
'description' => $contact->description,
'job' => $contact->job,
'company' => $contact->company,
];
$contactsCollection->push($contactItem);
}
}
return view('people.index')
->withTotalRecords($allContacts->count())
->withContacts($contactsCollection)
->withArchived($numberArchivedContacts)
->withTags($tags);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment