Сортировка и размер страницы через конфиг

This commit is contained in:
2022-09-04 09:24:09 +08:00
parent b65ab2cca0
commit a868b677f0
4 changed files with 20 additions and 6 deletions

View File

@@ -18,6 +18,15 @@ class HomeController extends Controller
$this->ini = new PlaylistProcessor();
}
/**
* @return int
*/
protected function getPageSize(): int
{
$size = config('app.page_size');
return empty($size) || $size < 5 || $size > 100 ? 10 : $size;
}
/**
* @throws Exception
*/
@@ -28,11 +37,12 @@ class HomeController extends Controller
Flight::redirect(base_url($id));
die;
}
$per_page = 10;
$list = $this->ini->playlists
->where('redirect_id', null)
// ->sortBy('id')
->forPage($page, $per_page);
$per_page = $this->getPageSize();
$list = $this->ini->playlists->where('redirect_id', null);
if (config('app.sort_by')) {
$list = $list->sortBy(config('app.sort_by'));
}
$list = $list->forPage($page, $per_page);
view('list', [
'updated_at' => $this->ini->updatedAt(),
'count' => $this->ini->playlists->count(),