Created
January 20, 2020 02:18
-
-
Save djaiss/cef7e730182a8b787c20a4a1c3f56f14 to your computer and use it in GitHub Desktop.
ContactController
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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