adding actual useful feature
This commit is contained in:
125
app/Http/Controllers/TagviewController.php
Normal file
125
app/Http/Controllers/TagviewController.php
Normal file
@@ -0,0 +1,125 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\Category;
|
||||
use App\Models\Video;
|
||||
use App\Models\Banner;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
use App\Http\Requests;
|
||||
use Cviebrock\EloquentTaggable\Services\TagService;
|
||||
class TagviewController extends Controller
|
||||
|
||||
{
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function index($tag)
|
||||
{
|
||||
$tag = $video = Video::with('tags')->find($tag->id);
|
||||
return $tag;
|
||||
// $tag = Video::withAnyTags($tag)->first();
|
||||
// return $tag;
|
||||
// $video = Video::with('tags')->find($tag->id);
|
||||
// return redirect('t/' . $tag->normalized . '/' . $video->id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for creating a new resource.
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function create()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
public function showVideo($shortname, $id = null)
|
||||
{
|
||||
// return $shortname;
|
||||
|
||||
if (is_null($id)) {
|
||||
$video = Video::getRandom($shortname, true);
|
||||
if ($video instanceof HasMany) {
|
||||
$video = $video->first();
|
||||
}
|
||||
else {
|
||||
return redirect()->back()->with('error', 'tag is empty.');
|
||||
}
|
||||
return redirect('/t/' . $shortname . '/' . $video->id);
|
||||
} else {
|
||||
// Don't filter on specific video.
|
||||
// TODO: Add warning page
|
||||
$video = Video::withAnyTags($shortname)->find($id);
|
||||
}
|
||||
|
||||
if (is_null($video)) {
|
||||
return redirect()->back()->with('error', 'tag is empty.');
|
||||
}
|
||||
|
||||
$sfw = $video->tags->contains(function($key, $tag) {
|
||||
return $tag->normalized === 'sfw';
|
||||
});
|
||||
|
||||
return view('video', [
|
||||
'video' => $video,
|
||||
'related' => $shortname,
|
||||
'isTag' => true,
|
||||
'sfw' => $sfw,
|
||||
'banner' => Banner::getRandom($video->isSfw())]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Store a newly created resource in storage.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
/**
|
||||
* Display the specified resource.
|
||||
*
|
||||
* @param int $id
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function show($id)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for editing the specified resource.
|
||||
*
|
||||
* @param int $id
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function edit($id)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the specified resource in storage.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param int $id
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function update(Request $request, $id)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the specified resource from storage.
|
||||
*
|
||||
* @param int $id
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function destroy($id)
|
||||
{
|
||||
//
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user