2016-09-01 16:23:39 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace app\Http\Controllers\Admin;
|
|
|
|
|
|
|
|
use App\Album;
|
2016-09-02 10:42:05 +01:00
|
|
|
use App\Facade\Theme;
|
2016-09-01 16:23:39 +01:00
|
|
|
use App\Http\Controllers\Controller;
|
|
|
|
use App\Http\Requests;
|
|
|
|
use Illuminate\Http\Request;
|
|
|
|
use Illuminate\Support\Facades\App;
|
|
|
|
|
|
|
|
class AlbumController extends Controller
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Display a listing of the resource.
|
|
|
|
*
|
|
|
|
* @return \Illuminate\Http\Response
|
|
|
|
*/
|
|
|
|
public function index()
|
|
|
|
{
|
|
|
|
$this->authorize('admin-access');
|
|
|
|
|
|
|
|
$albums = Album::all()->sortBy('name');
|
|
|
|
|
2016-09-02 10:42:05 +01:00
|
|
|
return Theme::render('admin.list_albums', [
|
2016-09-01 16:23:39 +01:00
|
|
|
'albums' => $albums
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Show the form for creating a new resource.
|
|
|
|
*
|
|
|
|
* @return \Illuminate\Http\Response
|
|
|
|
*/
|
|
|
|
public function create()
|
|
|
|
{
|
|
|
|
$this->authorize('admin-access');
|
|
|
|
|
2016-09-02 10:42:05 +01:00
|
|
|
return Theme::render('admin.create_album');
|
2016-09-01 16:23:39 +01:00
|
|
|
}
|
|
|
|
|
2016-09-01 17:17:55 +01:00
|
|
|
public function delete($id)
|
2016-09-01 16:23:39 +01:00
|
|
|
{
|
|
|
|
$this->authorize('admin-access');
|
|
|
|
|
2016-09-02 21:27:50 +01:00
|
|
|
$album = AlbumController::loadAlbum($id);
|
2016-09-01 17:17:55 +01:00
|
|
|
|
2016-09-02 10:42:05 +01:00
|
|
|
return Theme::render('admin.delete_album', ['album' => $album]);
|
2016-09-01 16:23:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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');
|
|
|
|
|
2016-09-01 17:31:16 +01:00
|
|
|
$album = new Album();
|
|
|
|
$album->fromRequest($request)->save();
|
2016-09-01 16:23:39 +01:00
|
|
|
|
|
|
|
return redirect(route('albums.index'));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Display the specified resource.
|
|
|
|
*
|
|
|
|
* @param int $id
|
|
|
|
* @return \Illuminate\Http\Response
|
|
|
|
*/
|
|
|
|
public function show($id)
|
|
|
|
{
|
|
|
|
$this->authorize('admin-access');
|
|
|
|
|
2016-09-02 21:27:50 +01:00
|
|
|
$album = AlbumController::loadAlbum($id);
|
2016-09-01 16:23:39 +01:00
|
|
|
|
2016-09-02 10:42:05 +01:00
|
|
|
return Theme::render('admin.show_album', ['album' => $album]);
|
2016-09-01 16:23:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Show the form for editing the specified resource.
|
|
|
|
*
|
|
|
|
* @param int $id
|
|
|
|
* @return \Illuminate\Http\Response
|
|
|
|
*/
|
|
|
|
public function edit($id)
|
|
|
|
{
|
|
|
|
$this->authorize('admin-access');
|
2016-09-01 17:31:16 +01:00
|
|
|
|
2016-09-02 21:27:50 +01:00
|
|
|
$album = AlbumController::loadAlbum($id);
|
2016-09-01 17:31:16 +01:00
|
|
|
|
2016-09-02 10:42:05 +01:00
|
|
|
return Theme::render('admin.edit_album', ['album' => $album]);
|
2016-09-01 16:23:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Update the specified resource in storage.
|
|
|
|
*
|
|
|
|
* @param \Illuminate\Http\Request $request
|
|
|
|
* @param int $id
|
|
|
|
* @return \Illuminate\Http\Response
|
|
|
|
*/
|
2016-09-01 17:31:16 +01:00
|
|
|
public function update(Requests\StoreAlbumRequest $request, $id)
|
2016-09-01 16:23:39 +01:00
|
|
|
{
|
|
|
|
$this->authorize('admin-access');
|
2016-09-01 17:31:16 +01:00
|
|
|
|
2016-09-02 21:27:50 +01:00
|
|
|
$album = AlbumController::loadAlbum($id);
|
2016-09-01 17:31:16 +01:00
|
|
|
$album->fromRequest($request)->save();
|
|
|
|
|
2016-09-02 10:42:05 +01:00
|
|
|
return Theme::render('admin.show_album', ['album' => $album]);
|
2016-09-01 16:23:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Remove the specified resource from storage.
|
|
|
|
*
|
|
|
|
* @param int $id
|
|
|
|
* @return \Illuminate\Http\Response
|
|
|
|
*/
|
|
|
|
public function destroy($id)
|
|
|
|
{
|
|
|
|
$this->authorize('admin-access');
|
2016-09-01 17:17:55 +01:00
|
|
|
|
2016-09-01 17:31:16 +01:00
|
|
|
$album = $this->loadAlbum($id);
|
|
|
|
$album->delete();
|
|
|
|
|
|
|
|
return redirect(route('albums.index'));
|
|
|
|
}
|
|
|
|
|
2016-09-02 21:27:50 +01:00
|
|
|
/**
|
|
|
|
* @param $id
|
|
|
|
* @return Album
|
|
|
|
*/
|
|
|
|
public static function loadAlbum($id)
|
2016-09-01 17:31:16 +01:00
|
|
|
{
|
2016-09-02 21:27:50 +01:00
|
|
|
$album = Album::where('id', intval($id))->first();
|
2016-09-01 17:17:55 +01:00
|
|
|
if (is_null($album))
|
|
|
|
{
|
|
|
|
App::abort(404);
|
2016-09-01 17:31:16 +01:00
|
|
|
return null;
|
2016-09-01 17:17:55 +01:00
|
|
|
}
|
|
|
|
|
2016-09-01 17:31:16 +01:00
|
|
|
return $album;
|
2016-09-01 16:23:39 +01:00
|
|
|
}
|
|
|
|
}
|