|
1
|
|
|
<?php namespace WITR\Http\Controllers\Admin; |
|
2
|
|
|
|
|
3
|
|
|
use WITR\Http\Requests\Admin\Event as Requests; |
|
4
|
|
|
use WITR\Http\Controllers\Controller; |
|
5
|
|
|
use WITR\Event; |
|
6
|
|
|
use Carbon\Carbon; |
|
7
|
|
|
use Input; |
|
8
|
|
|
use File; |
|
9
|
|
|
|
|
10
|
|
|
use Illuminate\Http\Request; |
|
11
|
|
|
|
|
12
|
|
|
class EventController 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 Events. |
|
22
|
|
|
* |
|
23
|
|
|
* @return Response |
|
24
|
|
|
*/ |
|
25
|
|
|
public function index() |
|
26
|
|
|
{ |
|
27
|
|
|
$events = Event::where('type', 'SLIDER')->orderBy('date', 'desc')->get(); |
|
28
|
|
|
return view('admin.events.index', ['events' => $events]); |
|
29
|
|
|
} |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* Display a listing of the resource. |
|
33
|
|
|
* |
|
34
|
|
|
* @return Response |
|
35
|
|
|
*/ |
|
36
|
|
|
public function new_event() |
|
37
|
|
|
{ |
|
38
|
|
|
return view('admin.events.create'); |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* Save the new Event |
|
43
|
|
|
* |
|
44
|
|
|
* @return Response |
|
45
|
|
|
*/ |
|
46
|
|
|
public function create(Requests\CreateRequest $request) |
|
47
|
|
|
{ |
|
48
|
|
|
$input = $request->all(); |
|
49
|
|
|
$event = new Event($input); |
|
50
|
|
|
$event->date = Carbon::createFromFormat('m/d/Y', $input['date']); |
|
|
|
|
|
|
51
|
|
|
$event->type = 'SLIDER'; |
|
|
|
|
|
|
52
|
|
|
$file = $request->file('picture'); |
|
53
|
|
|
$event->uploadFile('picture', $file); |
|
54
|
|
|
$event->save(); |
|
55
|
|
|
return redirect()->route('admin.events.index') |
|
56
|
|
|
->with('success', 'Event Saved!'); |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
public function edit($id) |
|
60
|
|
|
{ |
|
61
|
|
|
$event = Event::findOrFail($id); |
|
62
|
|
|
|
|
63
|
|
|
return view('admin.events.edit', ['event' => $event]); |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
public function update(Requests\UpdateRequest $request, $id) |
|
67
|
|
|
{ |
|
68
|
|
|
$event = Event::findOrFail($id); |
|
69
|
|
|
$event->fill($request->except(['date', 'picture'])); |
|
70
|
|
|
|
|
71
|
|
|
if ($request->hasFile('picture')) |
|
72
|
|
|
{ |
|
73
|
|
|
$file = $request->file('picture'); |
|
74
|
|
|
$event->uploadFile('picture', $file); |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
$date = Carbon::createFromFormat('m/d/Y', $request->input('date')); |
|
|
|
|
|
|
78
|
|
|
$event->date = $date; |
|
79
|
|
|
|
|
80
|
|
|
$event->save(); |
|
81
|
|
|
return redirect()->route('admin.events.index') |
|
82
|
|
|
->with('success', 'Event Saved!'); |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
View Code Duplication |
public function delete($id) |
|
|
|
|
|
|
86
|
|
|
{ |
|
87
|
|
|
$event = Event::findOrFail($id); |
|
88
|
|
|
File::delete(public_path().'/img/events/'.$event->picture); |
|
89
|
|
|
Event::destroy($id); |
|
90
|
|
|
return redirect()->route('admin.events.index') |
|
91
|
|
|
->with('success', 'Event Deleted!'); |
|
92
|
|
|
} |
|
93
|
|
|
|
|
94
|
|
|
} |
|
95
|
|
|
|
Since your code implements the magic setter
_set, this function will be called for any write access on an undefined variable. You can add the@propertyannotation to your class or interface to document the existence of this variable.Since the property has write access only, you can use the @property-write annotation instead.
Of course, you may also just have mistyped another name, in which case you should fix the error.
See also the PhpDoc documentation for @property.