jonnybarnes.uk/app/Http/Controllers/BookmarksController.php

52 lines
1.1 KiB
PHP
Raw Normal View History

2017-10-10 15:58:07 +01:00
<?php
declare(strict_types=1);
2017-10-10 15:58:07 +01:00
namespace App\Http\Controllers;
2017-12-19 16:00:42 +00:00
use App\Models\Bookmark;
use Illuminate\View\View;
2017-10-10 15:58:07 +01:00
class BookmarksController extends Controller
{
/**
* Show the most recent bookmarks.
*
* @return View
*/
public function index(): View
2017-10-10 15:58:07 +01:00
{
2017-10-11 18:04:05 +01:00
$bookmarks = Bookmark::latest()->with('tags')->withCount('tags')->paginate(10);
2017-10-10 15:58:07 +01:00
return view('bookmarks.index', compact('bookmarks'));
}
2017-10-10 16:17:29 +01:00
/**
* Show a single bookmark.
*
2022-07-09 10:08:26 +01:00
* @param Bookmark $bookmark
* @return View
*/
public function show(Bookmark $bookmark): View
2017-10-10 16:17:29 +01:00
{
2017-10-11 18:04:05 +01:00
$bookmark->loadMissing('tags');
2017-10-10 16:17:29 +01:00
return view('bookmarks.show', compact('bookmark'));
}
2022-08-14 17:56:21 +01:00
/**
* Show bookmakrs tagged with a specific tag.
*
* @param string $tag
* @return View
*/
public function tagged(string $tag): View
{
$bookmarks = Bookmark::whereHas('tags', function ($query) use ($tag) {
$query->where('tag', $tag);
})->latest()->with('tags')->withCount('tags')->paginate(10);
return view('bookmarks.tagged', compact('bookmarks', 'tag'));
}
2017-10-10 15:58:07 +01:00
}