Files
Gw0bm/.Trash-1000/files/TagController.php
2024-03-17 16:30:27 +01:00

43 lines
1.0 KiB
PHP

<?php
namespace App\Http\Controllers;
use App\Models\Tag;
use App\Models\Video;
use Illuminate\Http\Request;
class TagController extends Controller
{
/**
* Display a listing of the resource.
*
* @return \Illuminate\View\View
*/
public function index()
{
return view('tags', ['tags' => Tag::all()]);
}
/**
* Display the specified resource.
*
* @param string $normalized
* @param int|null $id
* @return \Illuminate\Http\RedirectResponse|\Illuminate\View\View
*/
public function showVideo($tagName)
{
// Retrieve the tag based on the provided tag name
$tag = Tag::where('name', $tagName)->firstOrFail();
// Get a random video related to the tag
$randomVideo = \App\Models\Video::getSingleRandom($tag);
// Pass the tag and the random video to your view
return view('tag.show')->with(compact('tag', 'randomVideo'));
}
// Define other CRUD operations for tags as needed.
}