blue-twilight/app/Http/Controllers/Gallery/AlbumController.php

44 lines
994 B
PHP

<?php
namespace App\Http\Controllers\Gallery;
use App\Album;
use App\Facade\Theme;
use App\Facade\UserConfig;
use App\Http\Controllers\Controller;
use App\Http\Requests;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
class AlbumController extends Controller
{
public function index($albumUrlAlias)
{
$album = AlbumController::loadAlbum($albumUrlAlias);
$photos = $album->photos()
->orderBy(DB::raw('COALESCE(taken_at, created_at)'))
->paginate(UserConfig::get('items_per_page_admin'));
return Theme::render('gallery.album', [
'album' => $album,
'photos' => $photos
]);
}
/**
* @param $id
* @return Album
*/
private static function loadAlbum($urlAlias)
{
$album = Album::where('url_alias', $urlAlias)->first();
if (is_null($album))
{
App::abort(404);
return null;
}
return $album;
}
}