Albums can now be deleted and the "Albums" link goes to the albums index page

This commit is contained in:
Andy Heathershaw 2016-09-01 17:17:55 +01:00
parent 3ce613b801
commit b4f35649c2
5 changed files with 74 additions and 22 deletions

View File

@ -38,11 +38,17 @@ class AlbumController extends Controller
return view('admin.create_album');
}
public function delete()
public function delete($id)
{
$this->authorize('admin-access');
return view('admin.delete_album');
$album = Album::all()->where('id', intval($id))->first();
if (is_null($album))
{
App::abort(404);
}
return view('admin.delete_album', ['album' => $album]);
}
/**
@ -112,5 +118,14 @@ class AlbumController extends Controller
public function destroy($id)
{
$this->authorize('admin-access');
$album = Album::all()->where('id', intval($id))->first();
if (is_null($album))
{
App::abort(404);
}
$album->delete();
return redirect(route('albums.index'));
}
}

View File

@ -5,7 +5,12 @@ return [
'create_album_intro' => 'Photo albums contain individual photographs together in the same way as a physical photo album or memory book.',
'create_album_intro2' => 'Complete the form below to create a photo album.',
'create_album_link' => 'Create album',
'delete_album' => 'Delete album :name',
'delete_album_confirm' => 'Are you sure you want to permanently delete this album and all its contents?',
'delete_album_warning' => 'This is a permanent action that cannot be undone!',
'list_albums_name_column' => 'Album name',
'no_albums_text' => 'You have no photo albums yet. Click the button below to create one.',
'no_albums_title' => 'No Photo Albums',
'stats_albums' => 'album|albums',
'stats_panel' => 'Statistics'
];

View File

@ -0,0 +1,22 @@
@extends('layouts.app')
@section('title', trans('admin.delete_album', ['name' => $album->name]))
@section('content')
<div class="container">
<div class="row">
<div class="col-xs-12">
<h1>@yield('title')</h1>
<p>@lang('admin.delete_album_confirm', ['name' => $album->name])</p>
<div class="alert alert-warning">
@lang('admin.delete_album_warning')
</div>
<div class="form-actions">
{!! Form::open(['url' => route('albums.destroy', ['id' => $album->id]), 'method' => 'DELETE']) !!}
<a href="{{ route('albums.show', ['id' => $album->id]) }}" class="btn btn-default">@lang('forms.cancel_action')</a>
{!! Form::submit(trans('forms.delete_action'), ['class' => 'btn btn-danger']) !!}
{!! Form::close() !!}
</div>
</div>
</div>
</div>
@endsection

View File

@ -5,25 +5,35 @@
<div class="container">
<div class="row">
<div class="col-xs-12">
<table class="table table-hover table-striped">
<thead>
<tr>
<th>@lang('admin.list_albums_name_column')</th>
<th></th>
</tr>
</thead>
<tbody>
@foreach ($albums as $album)
<tr>
<td><a href="{{ route('albums.show', ['id' => $album->id]) }}">{{ $album->name }}</a></td>
<td class="text-right">
<a href="{{ route('albums.edit', ['id' => $album->id]) }}" class="btn btn-default">@lang('forms.edit_action')</a>
<a href="{{ route('albums.delete', ['id' => $album->id]) }}" class="btn btn-danger">@lang('forms.delete_action')</a>
</td>
</tr>
@endforeach
</tbody>
</table>
@if (count($albums) == 0)
<div class="text-center">
<h3>@lang('admin.no_albums_title')</h3>
<p>@lang('admin.no_albums_text')</p>
<p style="margin-top: 40px;">
<a href="{{ route('albums.create') }}" class="btn btn-lg btn-success">@lang('admin.create_album')</a>
</p>
</div>
@else
<table class="table table-hover table-striped">
<thead>
<tr>
<th>@lang('admin.list_albums_name_column')</th>
<th></th>
</tr>
</thead>
<tbody>
@foreach ($albums as $album)
<tr>
<td><a href="{{ route('albums.show', ['id' => $album->id]) }}">{{ $album->name }}</a></td>
<td class="text-right">
<a href="{{ route('albums.edit', ['id' => $album->id]) }}" class="btn btn-default">@lang('forms.edit_action')</a>
<a href="{{ route('albums.delete', ['id' => $album->id]) }}" class="btn btn-danger">@lang('forms.delete_action')</a>
</td>
</tr>
@endforeach
</tbody>
</table>
@endif
</div>
</div>
</div>

View File

@ -35,7 +35,7 @@
<ul class="dropdown-menu">
<li><a href="{{ route('admin') }}">@lang('global.nav_admin_control')</a></li>
<li role="separator" class="divider"></li>
<li><a href="{{ route('admin') }}">@lang('global.nav_admin_albums')</a></li>
<li><a href="{{ route('albums.index') }}">@lang('global.nav_admin_albums')</a></li>
</ul>
</li>
@endcan