|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Transmissor\Http\Controllers\Admin; |
|
4
|
|
|
|
|
5
|
|
|
use Illuminate\Http\Request; |
|
6
|
|
|
use Transmissor\Http\Controllers\Controller; |
|
7
|
|
|
use Transmissor\Services\NotificationService; |
|
8
|
|
|
use Transmissor\Http\Requests\NotificationCreateRequest; |
|
9
|
|
|
use Transmissor\Http\Requests\NotificationUpdateRequest; |
|
10
|
|
|
|
|
11
|
|
|
class NotificationController extends Controller |
|
12
|
|
|
{ |
|
13
|
|
|
public function __construct(NotificationService $notificationService) |
|
14
|
|
|
{ |
|
15
|
|
|
$this->service = $notificationService; |
|
|
|
|
|
|
16
|
|
|
} |
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* Display a listing of the resource. |
|
20
|
|
|
* |
|
21
|
|
|
* @return \Illuminate\Http\Response |
|
22
|
|
|
*/ |
|
23
|
|
|
public function index(Request $request) |
|
|
|
|
|
|
24
|
|
|
{ |
|
25
|
|
|
$notifications = $this->service->paginated(); |
|
26
|
|
|
return view('transmissor::admin.notifications.index')->with('notifications', $notifications); |
|
|
|
|
|
|
27
|
|
|
} |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* Display a listing of the resource searched. |
|
31
|
|
|
* |
|
32
|
|
|
* @return \Illuminate\Http\Response |
|
33
|
|
|
*/ |
|
34
|
|
|
public function search(Request $request) |
|
35
|
|
|
{ |
|
36
|
|
|
$notifications = $this->service->search($request->search, null); |
|
37
|
|
|
return view('transmissor::admin.notifications.index')->with('notifications', $notifications); |
|
|
|
|
|
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* Show the form for creating a new resource. |
|
42
|
|
|
* |
|
43
|
|
|
* @return \Illuminate\Http\Response |
|
44
|
|
|
*/ |
|
45
|
|
|
public function create() |
|
46
|
|
|
{ |
|
47
|
|
|
return view('transmissor::admin.notifications.create'); |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
/** |
|
51
|
|
|
* Store a newly created resource in storage. |
|
52
|
|
|
* |
|
53
|
|
|
* @param \Illuminate\Http\NotificationCreateRequest $request |
|
54
|
|
|
* @return \Illuminate\Http\Response |
|
55
|
|
|
*/ |
|
56
|
|
|
public function store(NotificationCreateRequest $request) |
|
57
|
|
|
{ |
|
58
|
|
|
$result = $this->service->create($request->except('_token')); |
|
59
|
|
|
|
|
60
|
|
|
if ($result && is_object($result)) { |
|
61
|
|
|
return redirect('admin/notifications/'.$result->id.'/edit')->with('message', 'Successfully created'); |
|
62
|
|
|
} elseif ($result) { |
|
63
|
|
|
return redirect('admin/notifications')->with('message', 'Successfully created'); |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
return redirect('admin/notifications')->with('errors', ['Failed to create']); |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
/** |
|
70
|
|
|
* Show the form for editing the specified resource. |
|
71
|
|
|
* |
|
72
|
|
|
* @param int $id |
|
73
|
|
|
* @return \Illuminate\Http\Response |
|
74
|
|
|
*/ |
|
75
|
|
|
public function edit(Request $request, $id) |
|
|
|
|
|
|
76
|
|
|
{ |
|
77
|
|
|
$notification = $this->service->find($id); |
|
78
|
|
|
return view('transmissor::admin.notifications.edit')->with('notification', $notification); |
|
|
|
|
|
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
/** |
|
82
|
|
|
* Update the specified resource in storage. |
|
83
|
|
|
* |
|
84
|
|
|
* @param \Illuminate\Http\NotificationUpdateRequest $request |
|
85
|
|
|
* @param int $id |
|
86
|
|
|
* @return \Illuminate\Http\Response |
|
87
|
|
|
*/ |
|
88
|
|
|
public function update(NotificationUpdateRequest $request, $id) |
|
89
|
|
|
{ |
|
90
|
|
|
$result = $this->service->update($id, $request->except('_token')); |
|
91
|
|
|
|
|
92
|
|
|
if ($result) { |
|
93
|
|
|
return back()->with('message', 'Successfully updated'); |
|
94
|
|
|
} |
|
95
|
|
|
|
|
96
|
|
|
return back()->with('errors', ['Failed to update']); |
|
97
|
|
|
} |
|
98
|
|
|
|
|
99
|
|
|
/** |
|
100
|
|
|
* Remove the specified resource from storage. |
|
101
|
|
|
* |
|
102
|
|
|
* @param int $id |
|
103
|
|
|
* @return \Illuminate\Http\Response |
|
104
|
|
|
*/ |
|
105
|
|
View Code Duplication |
public function destroy(Request $request, $id) |
|
|
|
|
|
|
106
|
|
|
{ |
|
107
|
|
|
$result = $this->service->destroy($id); |
|
108
|
|
|
|
|
109
|
|
|
if ($result) { |
|
110
|
|
|
return redirect('admin/notifications')->with('message', 'Successfully deleted'); |
|
111
|
|
|
} |
|
112
|
|
|
|
|
113
|
|
|
return redirect('admin/notifications')->with('errors', ['Failed to delete']); |
|
114
|
|
|
} |
|
115
|
|
|
} |
|
116
|
|
|
|
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: