Files
UNIT3D-Community-Edition/app/Http/Controllers/CategoryController.php
2020-03-05 10:46:14 -05:00

58 lines
1.8 KiB
PHP
Executable File

<?php
/**
* NOTICE OF LICENSE.
*
* UNIT3D Community Edition is open-sourced software licensed under the GNU Affero General Public License v3.0
* The details is bundled with this project in the file LICENSE.txt.
*
* @project UNIT3D Community Edition
*
* @author HDVinnie <hdinnovations@protonmail.com>
* @license https://www.gnu.org/licenses/agpl-3.0.en.html/ GNU Affero General Public License v3.0
*/
namespace App\Http\Controllers;
use App\Models\Category;
use App\Models\PersonalFreeleech;
use App\Models\Torrent;
use Illuminate\Http\Request;
class CategoryController extends Controller
{
/**
* Display All Categories.
*
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
*/
public function index()
{
$categories = Category::withCount('torrents')->get()->sortBy('position');
return view('category.index', ['categories' => $categories]);
}
/**
* Show A Category.
*
* @param \Illuminate\Http\Request $request
* @param \App\Models\Category $id
*
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
*/
public function show(Request $request, $id)
{
$user = $request->user();
$category = Category::select(['id', 'name'])->findOrFail($id);
$torrents = Torrent::with(['user', 'category'])->withCount(['thanks', 'comments'])->where('category_id', '=', $id)->orderBy('sticky', 'desc')->latest()->paginate(25);
$personal_freeleech = PersonalFreeleech::where('user_id', '=', $user->id)->first();
return view('category.show', [
'torrents' => $torrents,
'user' => $user,
'category' => $category,
'personal_freeleech' => $personal_freeleech,
]);
}
}