EloquentAlbumRepository::create()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
dl 0
loc 4
rs 10
c 2
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
1
<?php namespace JeroenG\LaravelPhotoGallery\Repositories;
2
3
use Illuminate\Contracts\Filesystem\Factory as Filesystem;
4
use JeroenG\LaravelPhotoGallery\Models\Album;
5
6
class EloquentAlbumRepository implements AlbumRepository {
7
	
8
	public function all()
9
	{
10
		return Album::all();
11
	}
12
13
	public function find($id)
14
	{
15
		return Album::find($id);
16
	}
17
18
	public function findOrFail($id)
19
	{
20
		return Album::findOrFail($id);
21
	}
22
23
	public function create($input)
24
	{
25
		return Album::create($input);
26
	}
27
28
	public function update($id, $input)
29
	{
30
		$album = Album::find($id);
31
		$album->album_name = $input['album_name'];
32
		$album->album_description = $input['album_description'];
33
		$album->touch();
34
		return $album->save();
35
	}
36
37
	public function delete($id, PhotoRepository $photos, Filesystem $storage)
38
	{
39
		$album = Album::find($id);
40
		$albumPhotos = $album->photos;
41
42
		foreach ($albumPhotos as $photo) {
43
			$photos->delete($photo->photo_id, $storage);
44
		}
45
		return $album->delete();
46
	}
47
48
	public function forceDelete($id, PhotoRepository $photos, Filesystem $storage)
49
	{
50
		$album = Album::find($id);
51
		$albumPhotos = $album->photos;
52
53
		foreach ($albumPhotos as $photo) {
54
			$photos->forceDelete($photo->photo_id, $storage);
55
		}
56
		return $album->forceDelete();
57
	}
58
59
	public function restore($id, PhotoRepository $photos, Filesystem $storage)
60
	{
61
		$album = Album::withTrashed()->find($id);
62
		$photos->restoreFromAlbum($id, $storage);
63
		return $album->restore();
64
	}
65
}