2017-10-10 15:58:07 +01:00
|
|
|
<?php
|
|
|
|
|
2018-01-15 14:02:13 +00:00
|
|
|
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;
|
2018-01-15 14:02:13 +00:00
|
|
|
use Illuminate\View\View;
|
2017-10-10 15:58:07 +01:00
|
|
|
|
|
|
|
class BookmarksController extends Controller
|
|
|
|
{
|
2018-01-15 14:02:13 +00:00
|
|
|
/**
|
|
|
|
* Show the most recent bookmarks.
|
|
|
|
*/
|
|
|
|
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
|
|
|
|
2018-01-15 14:02:13 +00:00
|
|
|
/**
|
|
|
|
* Show a single bookmark.
|
|
|
|
*/
|
|
|
|
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
|
|
|
|
|
|
|
/**
|
2022-08-14 18:07:38 +01:00
|
|
|
* Show bookmarks tagged with a specific tag.
|
2022-08-14 17:56:21 +01:00
|
|
|
*/
|
|
|
|
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
|
|
|
}
|