authorize('admin-access'); $albums = Album::orderBy('name') ->withCount('photos') ->paginate(UserConfig::get('items_per_page')); return Theme::render('admin.list_albums', [ 'albums' => $albums ]); } /** * Show the form for creating a new resource. * * @return \Illuminate\Http\Response */ public function create() { $this->authorize('admin-access'); return Theme::render('admin.create_album'); } public function delete($id) { $this->authorize('admin-access'); $album = AlbumController::loadAlbum($id); return Theme::render('admin.delete_album', ['album' => $album]); } /** * Display the specified resource. * * @param int $id * @return \Illuminate\Http\Response */ public function show(Request $request, $id) { $this->authorize('admin-access'); $album = AlbumController::loadAlbum($id); $photos = $album->photos() ->orderBy(DB::raw('COALESCE(taken_at, created_at)')) ->paginate(UserConfig::get('items_per_page_admin')); return Theme::render('admin.show_album', [ 'album' => $album, 'error' => $request->session()->get('error'), 'photos' => $photos ]); } /** * Store a newly created resource in storage. * * @param \Illuminate\Http\Request $request * @return \Illuminate\Http\Response */ public function store(Requests\StoreAlbumRequest $request) { $this->authorize('admin-access'); $album = new Album(); $album->fromRequest($request)->save(); return redirect(route('albums.index')); } /** * Show the form for editing the specified resource. * * @param int $id * @return \Illuminate\Http\Response */ public function edit($id) { $this->authorize('admin-access'); $album = AlbumController::loadAlbum($id); return Theme::render('admin.edit_album', ['album' => $album]); } public function monitorUpload($id, $uploadId) { $this->authorize('admin-access'); $upload = AlbumController::loadUpload($uploadId, $id); return Theme::render('admin.album_upload_progress', ['upload' => $upload, 'album' => $upload->album]); } public function monitorUploadJson($id, $uploadId) { $this->authorize('admin-access'); return response()->json(AlbumController::loadUpload($uploadId, $id)->toArray()); } /** * Update the specified resource in storage. * * @param \Illuminate\Http\Request $request * @param int $id * @return \Illuminate\Http\Response */ public function update(Requests\StoreAlbumRequest $request, $id) { $this->authorize('admin-access'); $album = AlbumController::loadAlbum($id); $album->fromRequest($request)->save(); return Theme::render('admin.show_album', ['album' => $album]); } /** * Remove the specified resource from storage. * * @param int $id * @return \Illuminate\Http\Response */ public function destroy($id) { $this->authorize('admin-access'); $album = $this->loadAlbum($id); $album->delete(); return redirect(route('albums.index')); } /** * @param $id * @return Album */ public static function loadAlbum($id) { $album = Album::where('id', intval($id))->first(); if (is_null($album)) { App::abort(404); return null; } return $album; } /** * @param $id * @param $albumId * @return Upload|null */ private static function loadUpload($id, $albumId) { $upload = Upload::where([ 'id' => intval($id), 'album_id' => intval($albumId) ])->first(); if (is_null($upload)) { App::abort(404); return null; } return $upload; } }