public function loadUserInfo() { $peopleWithAvatars = []; $avatars = Avatar::where('attachment_type', 'RainLab\\User\\Models\\User')->where('field', 'avatar')->get(); foreach ($avatars as $avatr) { $this->avatars[$avatr->attachment_id] = ['t600' => $avatr->getThumb(600, 600), 't200' => $avatr->getThumb(200, 200), 'filename' => $avatr->filename]; $peopleWithAvatars[] = $avatr->attachment_id; } // Set Pagination parameters $this->perPage = $this->property('PicsPerPage', 12); $this->currentPage = input('page', 1); $sort3 = null; /* * Sorting */ switch ($this->sort) { case 'last': $sort1 = 'surname'; $sort2 = 'name'; break; case 'given': $sort1 = 'name'; $sort2 = 'surname'; break; default: $sort1 = 'primary_usergroup'; $sort2 = 'surname'; $sort3 = 'name'; } $people = user::wherein('id', $peopleWithAvatars)->orderBy($sort1)->orderBy($sort2); if ($sort3) { $people->orderBy($sort3); } $this->people = $people->paginate($this->perPage, $this->currentPage); /* * Pagination */ if ($this->people) { $queryArr = []; $queryArr['sort'] = $this->sort; $queryArr['page'] = ''; $paginationUrl = Request::url() . '?' . http_build_query($queryArr); if ($this->currentPage > ($this->lastPage = $this->people->lastPage()) && $this->currentPage > 1) { return Redirect::to($paginationUrl . $this->lastPage); } $this->firstItem = $this->people->firstItem(); $this->lastItem = $this->people->lastItem(); $this->total = $this->people->total(); $this->paginationUrl = $paginationUrl; } return $this->people; }