|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace JeroenG\LaravelPhotoGallery\Controllers; |
|
4
|
|
|
|
|
5
|
|
|
use Illuminate\Http\Request; |
|
6
|
|
|
use JeroenG\LaravelPhotoGallery\Entities as Entity; |
|
7
|
|
|
|
|
8
|
|
|
class AlbumsController extends Controller |
|
9
|
|
|
{ |
|
10
|
|
|
/** |
|
11
|
|
|
* Show the form for creating a new album. |
|
12
|
|
|
* |
|
13
|
|
|
* @return \Illuminate\View\View |
|
14
|
|
|
*/ |
|
15
|
|
|
public function create() |
|
16
|
|
|
{ |
|
17
|
|
|
$data = array('type' => 'album'); |
|
18
|
|
|
return view('gallery::new', $data)->with('form', 'gallery::partials.new-album'); |
|
19
|
|
|
} |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* Store a newly created album in storage. |
|
23
|
|
|
* |
|
24
|
|
|
* @param $request |
|
25
|
|
|
* @return \Illuminate\View\View |
|
26
|
|
|
*/ |
|
27
|
|
|
public function store(Request $request) |
|
28
|
|
|
{ |
|
29
|
|
|
$this->validate($request, [ |
|
30
|
|
|
'album_name' => 'required', |
|
31
|
|
|
'album_description' => 'max:255', |
|
32
|
|
|
]); |
|
33
|
|
|
|
|
34
|
|
|
$album = new Entity\Album(); |
|
35
|
|
|
$album->map([ |
|
36
|
|
|
'name' => $request->input('album_name'), |
|
37
|
|
|
'description' => $request->input('album_description'), |
|
38
|
|
|
'order' => 0, |
|
39
|
|
|
]); |
|
40
|
|
|
|
|
41
|
|
|
\Gallery::album()->add($album); |
|
42
|
|
|
|
|
43
|
|
|
return \Redirect::route('gallery')->with('alertsuccess', \Lang::get('gallery::gallery.creation')); |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* Display the specified albums' photos. |
|
48
|
|
|
* |
|
49
|
|
|
* @param int $id Id of the album |
|
50
|
|
|
* @return \Illuminate\View\View |
|
51
|
|
|
*/ |
|
52
|
|
|
public function show($id) |
|
53
|
|
|
{ |
|
54
|
|
|
$album = \Gallery::album()->find($id); |
|
55
|
|
|
$albumPhotos = \Gallery::photo()->findByAlbumId($id); |
|
56
|
|
|
return view('gallery::album', ['album' => $album, 'albumPhotos' => $albumPhotos]); |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
/** |
|
60
|
|
|
* Show the form for editing the specified album. |
|
61
|
|
|
* |
|
62
|
|
|
* @param int $id Id of the album |
|
63
|
|
|
* @return \Illuminate\View\View |
|
64
|
|
|
*/ |
|
65
|
|
|
public function edit($id) |
|
66
|
|
|
{ |
|
67
|
|
|
$album = \Gallery::album()->find($id); |
|
68
|
|
|
|
|
69
|
|
|
$data = array('type' => 'album', 'album' => $album); |
|
70
|
|
|
return view('gallery::edit', $data)->with('form', 'gallery::partials.edit-album'); |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
/** |
|
74
|
|
|
* Update the specified album in the database. |
|
75
|
|
|
* |
|
76
|
|
|
* @param int $id Id of the album |
|
77
|
|
|
* @return \Illuminate\View\View |
|
78
|
|
|
*/ |
|
79
|
|
|
public function update(Request $request, $id) |
|
80
|
|
|
{ |
|
81
|
|
|
$this->validate($request, [ |
|
82
|
|
|
'album_name' => 'required', |
|
83
|
|
|
'album_description' => 'max:255', |
|
84
|
|
|
]); |
|
85
|
|
|
|
|
86
|
|
|
$album = new Entity\Album(); |
|
87
|
|
|
$album->map([ |
|
88
|
|
|
'id' => $id, |
|
89
|
|
|
'name' => $request->input('album_name'), |
|
90
|
|
|
'description' => $request->input('album_description'), |
|
91
|
|
|
'order' => 0, |
|
92
|
|
|
]); |
|
93
|
|
|
|
|
94
|
|
|
\Gallery::album()->save($album); |
|
95
|
|
|
|
|
96
|
|
|
return \Redirect::route('gallery.album.show', ['id' => $id])->with('alertsuccess', \Lang::get('gallery::gallery.update')); |
|
97
|
|
|
} |
|
98
|
|
|
|
|
99
|
|
|
/** |
|
100
|
|
|
* Remove the specified album from the database. |
|
101
|
|
|
* |
|
102
|
|
|
* @param int $id Id of the album |
|
103
|
|
|
* @return \Illuminate\View\View |
|
104
|
|
|
*/ |
|
105
|
|
|
public function destroy($id) |
|
106
|
|
|
{ |
|
107
|
|
|
$album = new Entity\Album(); |
|
108
|
|
|
$album->map([ |
|
109
|
|
|
'id' => $id, |
|
110
|
|
|
]); |
|
111
|
|
|
\Gallery::album()->delete($album); |
|
112
|
|
|
return \Redirect::route("gallery")->with('alertsuccess', \Lang::get('gallery::gallery.removal')); |
|
113
|
|
|
} |
|
114
|
|
|
} |