ShowController   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 88
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 7

Importance

Changes 8
Bugs 0 Features 3
Metric Value
wmc 9
c 8
b 0
f 3
lcom 0
cbo 7
dl 0
loc 88
rs 10

7 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A index() 0 5 1
A new_show() 0 4 1
A create() 0 14 1
A edit() 0 6 1
A update() 0 21 3
A delete() 0 9 1
1
<?php namespace WITR\Http\Controllers\Admin;
2
3
use WITR\Http\Requests\Admin\Show as Requests;
4
use WITR\Http\Controllers\Controller;
5
use WITR\Show;
6
use Input;
7
use File;
8
use Carbon\Carbon;
9
10
use Illuminate\Http\Request;
11
12
class ShowController extends Controller {
13
14
	public function __construct()
15
	{
16
		$this->middleware('auth');
17
		$this->middleware('editor');
18
	}
19
	
20
	/**
21
	 * Display a listing of the Shows.
22
	 *
23
	 * @return Response
24
	 */
25
	public function index()
26
	{
27
		$shows = Show::orderBy('name', 'asc')->get();
28
		return view('admin.shows.index', ['shows' => $shows]);
29
	}
30
31
	/**
32
	 * Display a listing of the resource.
33
	 *
34
	 * @return Response
35
	 */
36
	public function new_show()
37
	{
38
		return view('admin.shows.create');
39
	}
40
41
	/**
42
	* Save the new Show.
43
	*
44
	*@return Response
45
	*/
46
	public function create(Requests\CreateRequest $request)
47
	{
48
		$show = new Show($request->except(['show_picture', 'slider_picture']));
49
50
		$showPicture = $request->file('show_picture');
51
		$show->uploadFile('show_picture', $showPicture);
52
53
		$sliderPicture = $request->file('slider_picture');
54
		$show->uploadFile('slider_picture', $sliderPicture);
55
56
		$show->save();
57
		return redirect()->route('admin.shows.index')
58
			->with('success', 'Show Saved!');
59
	}
60
61
	public function edit($id)
62
	{
63
		$show = Show::findOrFail($id);
64
65
		return view('admin.shows.edit', ['show' => $show]);
66
	}
67
68
	public function update(Requests\UpdateRequest $request, $id)
69
	{
70
		$show = Show::findOrFail($id);
71
		$show->fill($request->except(['show_picture', 'slider_picture']));
72
73
		if ($request->hasFile('show_picture')) 
74
		{
75
			$showPicture = $request->file('show_picture');
76
			$show->uploadFile('show_picture', $showPicture);
77
		}
78
79
		if ($request->hasFile('slider_picture')) 
80
		{
81
			$sliderPicture = $request->file('slider_picture');
82
			$show->uploadFile('slider_picture', $sliderPicture);
83
		}
84
85
		$show->save();
86
		return redirect()->route('admin.shows.index')
87
			->with('success', 'Show Saved!');
88
	}
89
90
	public function delete($id)
91
	{
92
		$show = Show::findOrFail($id);
93
		File::delete(public_path() . '/img/shows/' . $show->show_picture);
94
		File::delete(public_path() . '/img/slider/' . $show->slider_picture);
95
		Show::destroy($id);
96
		return redirect()->route('admin.shows.index')
97
			->with('success', 'Show Deleted!');
98
	}
99
}
100