Albums can now be edited. De-duplicated code in the AlbumController
This commit is contained in:
parent
b4f35649c2
commit
932f7017dc
@ -27,12 +27,11 @@ class Album extends Model
|
||||
protected $hidden = [
|
||||
];
|
||||
|
||||
public static function fromRequest(Request $request)
|
||||
public function fromRequest(Request $request)
|
||||
{
|
||||
$album = new Album();
|
||||
$album->name = $request->get('name');
|
||||
$album->description = $request->get('description');
|
||||
$this->name = $request->get('name');
|
||||
$this->description = $request->get('description');
|
||||
|
||||
return $album;
|
||||
return $this;
|
||||
}
|
||||
}
|
@ -42,11 +42,7 @@ class AlbumController extends Controller
|
||||
{
|
||||
$this->authorize('admin-access');
|
||||
|
||||
$album = Album::all()->where('id', intval($id))->first();
|
||||
if (is_null($album))
|
||||
{
|
||||
App::abort(404);
|
||||
}
|
||||
$album = $this->loadAlbum($id);
|
||||
|
||||
return view('admin.delete_album', ['album' => $album]);
|
||||
}
|
||||
@ -61,8 +57,8 @@ class AlbumController extends Controller
|
||||
{
|
||||
$this->authorize('admin-access');
|
||||
|
||||
$album = Album::fromRequest($request);
|
||||
$album->save();
|
||||
$album = new Album();
|
||||
$album->fromRequest($request)->save();
|
||||
|
||||
return redirect(route('albums.index'));
|
||||
}
|
||||
@ -77,11 +73,7 @@ class AlbumController extends Controller
|
||||
{
|
||||
$this->authorize('admin-access');
|
||||
|
||||
$album = Album::all()->where('id', intval($id))->first();
|
||||
if (is_null($album))
|
||||
{
|
||||
App::abort(404);
|
||||
}
|
||||
$album = $this->loadAlbum($id);
|
||||
|
||||
return view('admin.show_album', ['album' => $album]);
|
||||
}
|
||||
@ -95,6 +87,10 @@ class AlbumController extends Controller
|
||||
public function edit($id)
|
||||
{
|
||||
$this->authorize('admin-access');
|
||||
|
||||
$album = $this->loadAlbum($id);
|
||||
|
||||
return view('admin.edit_album', ['album' => $album]);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -104,9 +100,14 @@ class AlbumController extends Controller
|
||||
* @param int $id
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function update(Request $request, $id)
|
||||
public function update(Requests\StoreAlbumRequest $request, $id)
|
||||
{
|
||||
$this->authorize('admin-access');
|
||||
|
||||
$album = $this->loadAlbum($id);
|
||||
$album->fromRequest($request)->save();
|
||||
|
||||
return view('admin.show_album', ['album' => $album]);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -119,13 +120,21 @@ class AlbumController extends Controller
|
||||
{
|
||||
$this->authorize('admin-access');
|
||||
|
||||
$album = $this->loadAlbum($id);
|
||||
$album->delete();
|
||||
|
||||
return redirect(route('albums.index'));
|
||||
}
|
||||
|
||||
private function loadAlbum($id)
|
||||
{
|
||||
$album = Album::all()->where('id', intval($id))->first();
|
||||
if (is_null($album))
|
||||
{
|
||||
App::abort(404);
|
||||
return null;
|
||||
}
|
||||
|
||||
$album->delete();
|
||||
return redirect(route('albums.index'));
|
||||
return $album;
|
||||
}
|
||||
}
|
@ -5,5 +5,6 @@ return [
|
||||
'delete_action' => 'Delete',
|
||||
'description_label' => 'Description:',
|
||||
'edit_action' => 'Edit',
|
||||
'name_label' => 'Name:'
|
||||
'name_label' => 'Name:',
|
||||
'save_action' => 'Save Changes'
|
||||
];
|
@ -11,7 +11,7 @@
|
||||
@lang('admin.delete_album_warning')
|
||||
</div>
|
||||
<div class="form-actions">
|
||||
{!! Form::open(['url' => route('albums.destroy', ['id' => $album->id]), 'method' => 'DELETE']) !!}
|
||||
{!! Form::open(['route' => ['albums.destroy', $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() !!}
|
||||
|
42
resources/views/admin/edit_album.blade.php
Normal file
42
resources/views/admin/edit_album.blade.php
Normal file
@ -0,0 +1,42 @@
|
||||
@extends('layouts.app')
|
||||
@section('title', 'Gallery Admin')
|
||||
|
||||
@section('content')
|
||||
<div class="container">
|
||||
<div class="row">
|
||||
<div class="col-xs-12">
|
||||
<h1>@lang('admin.create_album')</h1>
|
||||
<p>@lang('admin.create_album_intro')</p>
|
||||
<p>@lang('admin.create_album_intro2')</p>
|
||||
<hr/>
|
||||
|
||||
@if (count($errors) > 0)
|
||||
<div class="alert alert-danger">
|
||||
<ul>
|
||||
@foreach ($errors->all() as $error)
|
||||
<li>{{ $error }}</li>
|
||||
@endforeach
|
||||
</ul>
|
||||
</div>
|
||||
@endif
|
||||
|
||||
{!! Form::model($album, ['route' => ['albums.update', $album->id], 'method' => 'PUT']) !!}
|
||||
<div class="form-group">
|
||||
{!! Form::label('name', trans('forms.name_label'), ['class' => 'control-label']) !!}
|
||||
{!! Form::text('name', old('name'), ['class' => 'form-control']) !!}
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
{!! Form::label('description', trans('forms.description_label'), ['class' => 'control-label']) !!}
|
||||
{!! Form::textarea('description', old('description'), ['class' => 'form-control']) !!}
|
||||
</div>
|
||||
|
||||
<div class="form-actions">
|
||||
{!! Form::submit(trans('forms.save_action'), ['class' => 'btn btn-success']) !!}
|
||||
<a href="{{ route('albums.show', ['id' => $album->id]) }}" class="btn btn-default">@lang('forms.cancel_action')</a>
|
||||
</div>
|
||||
{!! Form::close() !!}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@endsection
|
@ -8,7 +8,11 @@
|
||||
<div class="panel panel-default">
|
||||
<div class="panel-heading">@lang('admin.stats_panel')</div>
|
||||
<div class="panel-body">
|
||||
<p><b>{{ $album_count }}</b> {{ trans_choice('admin.stats_albums', $album_count) }}</p>
|
||||
<p>
|
||||
<a href="{{ route('albums.index') }}">
|
||||
<b>{{ $album_count }}</b> {{ trans_choice('admin.stats_albums', $album_count) }}
|
||||
</a>
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
@ -24,7 +24,10 @@
|
||||
<tbody>
|
||||
@foreach ($albums as $album)
|
||||
<tr>
|
||||
<td><a href="{{ route('albums.show', ['id' => $album->id]) }}">{{ $album->name }}</a></td>
|
||||
<td>
|
||||
<span style="font-size: 1.3em;"><a href="{{ route('albums.show', ['id' => $album->id]) }}">{{ $album->name }}</a></span><br/>
|
||||
<p>{{ $album->description }}</p>
|
||||
</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>
|
||||
@ -33,6 +36,10 @@
|
||||
@endforeach
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<div style="margin-top: 10px;">
|
||||
<a href="{{ route('albums.create') }}" class="btn btn-success"><i class="fa fa-fw fa-plus"></i> @lang('admin.create_album_link')</a>
|
||||
</div>
|
||||
@endif
|
||||
</div>
|
||||
</div>
|
||||
|
Loading…
Reference in New Issue
Block a user