jonnybarnes.uk/app/Http/Controllers/FrontPageController.php
Jonny Barnes 5ef23376be Work so far in refactoring front-end
- Mainly getting rid of existing css/js
- No longer linking to stuff like a11y.css
- Creating a FrontPageController to better deal with the home page
2019-07-26 10:40:56 +01:00

44 lines
949 B
PHP

<?php
namespace App\Http\Controllers;
use Exception;
use App\Models\Like;
use App\Models\Note;
use App\Models\Article;
use App\Models\Bookmark;
class FrontPageController extends Controller
{
/**
* Show all the recent activity.
*/
public function index()
{
$pageNumber = request()->query('page') ?? 1;
$notes = Note::latest()->get();
$articles = Article::latest()->get();
$bookmarks = Bookmark::latest()->get();
$likes = Like::latest()->get();
$allItems = collect($notes)
->merge($articles)
->merge($bookmarks)
->merge($likes)
->sortByDesc('updated_at')
->chunk(10);
$totalNumPages = $allItems->count();
$page = $allItems->get($pageNumber - 1);
if (is_null($page)) {
abort(404);
}
return view('front-page', [
'items' => $page,
]);
}
}