|
| 1 | +<?php |
| 2 | + |
| 3 | +declare(strict_types=1); |
| 4 | + |
| 5 | +/** |
| 6 | + * NOTICE OF LICENSE. |
| 7 | + * |
| 8 | + * UNIT3D Community Edition is open-sourced software licensed under the GNU Affero General Public License v3.0 |
| 9 | + * The details is bundled with this project in the file LICENSE.txt. |
| 10 | + * |
| 11 | + * @project UNIT3D Community Edition |
| 12 | + * |
| 13 | + * @author Roardom <roardom@protonmail.com> |
| 14 | + * @license https://www.gnu.org/licenses/agpl-3.0.en.html/ GNU Affero General Public License v3.0 |
| 15 | + */ |
| 16 | + |
| 17 | +namespace App\Http\Controllers\Staff; |
| 18 | + |
| 19 | +use App\Http\Controllers\Controller; |
| 20 | +use App\Http\Requests\Staff\StorePlaylistCategoryRequest; |
| 21 | +use App\Http\Requests\Staff\UpdatePlaylistCategoryRequest; |
| 22 | +use App\Models\Category; |
| 23 | +use App\Models\PlaylistCategory; |
| 24 | +use Exception; |
| 25 | + |
| 26 | +class PlaylistCategoryController extends Controller |
| 27 | +{ |
| 28 | + /** |
| 29 | + * Display all playlist categories. |
| 30 | + */ |
| 31 | + public function index(): \Illuminate\Contracts\View\Factory|\Illuminate\View\View |
| 32 | + { |
| 33 | + return view('Staff.playlist-category.index', [ |
| 34 | + 'playlistCategories' => PlaylistCategory::query()->orderBy('position')->get(), |
| 35 | + ]); |
| 36 | + } |
| 37 | + |
| 38 | + /** |
| 39 | + * Show form for creating a new category. |
| 40 | + */ |
| 41 | + public function create(): \Illuminate\Contracts\View\Factory|\Illuminate\View\View |
| 42 | + { |
| 43 | + return view('Staff.playlist-category.create'); |
| 44 | + } |
| 45 | + |
| 46 | + /** |
| 47 | + * Store a category. |
| 48 | + */ |
| 49 | + public function store(StorePlaylistCategoryRequest $request): \Illuminate\Http\RedirectResponse |
| 50 | + { |
| 51 | + PlaylistCategory::create($request->validated()); |
| 52 | + |
| 53 | + return to_route('staff.playlist_categories.index'); |
| 54 | + } |
| 55 | + |
| 56 | + /** |
| 57 | + * Playlist category edit form. |
| 58 | + */ |
| 59 | + public function edit(PlaylistCategory $playlistCategory): \Illuminate\Contracts\View\Factory|\Illuminate\View\View |
| 60 | + { |
| 61 | + return view('Staff.playlist-category.edit', [ |
| 62 | + 'playlistCategory' => $playlistCategory, |
| 63 | + ]); |
| 64 | + } |
| 65 | + |
| 66 | + /** |
| 67 | + * Update a playlist category. |
| 68 | + */ |
| 69 | + public function update(UpdatePlaylistCategoryRequest $request, PlaylistCategory $playlistCategory): \Illuminate\Http\RedirectResponse |
| 70 | + { |
| 71 | + $playlistCategory->update($request->validated()); |
| 72 | + |
| 73 | + return to_route('staff.playlist_categories.index'); |
| 74 | + } |
| 75 | + |
| 76 | + /** |
| 77 | + * Destroy a category. |
| 78 | + * |
| 79 | + * @throws Exception |
| 80 | + */ |
| 81 | + public function destroy(PlaylistCategory $playlistCategory): \Illuminate\Http\RedirectResponse |
| 82 | + { |
| 83 | + if ($playlistCategory->playlists()->exists()) { |
| 84 | + return to_route('staff.playlist_categories.index') |
| 85 | + ->withErrors('Can\'t delete playlist category that still contains playlists'); |
| 86 | + } |
| 87 | + |
| 88 | + $playlistCategory->delete(); |
| 89 | + |
| 90 | + return to_route('staff.playlist_categories.index'); |
| 91 | + } |
| 92 | +} |
0 commit comments