|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Transmissor\Http\Controllers\User; |
|
4
|
|
|
|
|
5
|
|
|
use Auth; |
|
6
|
|
|
use Illuminate\Http\Request; |
|
7
|
|
|
use Transmissor\Http\Controllers\User\Controller; |
|
8
|
|
|
use Transmissor\Services\NotificationService; |
|
9
|
|
|
|
|
10
|
|
|
class NotificationController extends Controller |
|
11
|
|
|
{ |
|
12
|
|
|
public function __construct(NotificationService $notificationService) |
|
13
|
|
|
{ |
|
14
|
|
|
$this->service = $notificationService; |
|
|
|
|
|
|
15
|
|
|
} |
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* Display a listing of the resource. |
|
19
|
|
|
* |
|
20
|
|
|
* @return \Illuminate\Http\Response |
|
21
|
|
|
*/ |
|
22
|
|
|
public function index(Request $request) |
|
|
|
|
|
|
23
|
|
|
{ |
|
24
|
|
|
$notifications = $this->service->userBasedPaginated(Auth::id()); |
|
25
|
|
|
$currentActor = Auth::user(); |
|
26
|
|
|
return view('transmissor::users.notifications.index') |
|
|
|
|
|
|
27
|
|
|
->with('notifications', $notifications)->with('currentActor', $currentActor); |
|
28
|
|
|
} |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* Display a listing of the resource searched. |
|
32
|
|
|
* |
|
33
|
|
|
* @return \Illuminate\Http\Response |
|
34
|
|
|
*/ |
|
35
|
|
|
public function search(Request $request) |
|
36
|
|
|
{ |
|
37
|
|
|
$notifications = $this->service->search($request->search, Auth::id()); |
|
38
|
|
|
return view('transmissor::users.notifications.index')->with('notifications', $notifications); |
|
|
|
|
|
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* Display the specified resource. |
|
43
|
|
|
* |
|
44
|
|
|
* @param int $id |
|
|
|
|
|
|
45
|
|
|
* @return \Illuminate\Http\Response |
|
46
|
|
|
*/ |
|
47
|
|
|
public function read($uuid) |
|
48
|
|
|
{ |
|
49
|
|
|
$notification = $this->service->findByUuid($uuid); |
|
50
|
|
|
$this->service->markAsRead($notification->id); |
|
51
|
|
|
|
|
52
|
|
|
return view('transmissor::users.notifications.show')->with('notification', $notification); |
|
|
|
|
|
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
/** |
|
56
|
|
|
* Remove the specified resource from storage. |
|
57
|
|
|
* |
|
58
|
|
|
* @param int $id |
|
59
|
|
|
* @return \Illuminate\Http\Response |
|
60
|
|
|
*/ |
|
61
|
|
View Code Duplication |
public function delete($id) |
|
|
|
|
|
|
62
|
|
|
{ |
|
63
|
|
|
$result = $this->service->destroy($id); |
|
64
|
|
|
|
|
65
|
|
|
if ($result) { |
|
66
|
|
|
return redirect('user/notifications')->with('message', 'Successfully deleted'); |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
return redirect('user/notifications')->with('errors', ['Failed to delete']); |
|
70
|
|
|
} |
|
71
|
|
|
} |
|
72
|
|
|
|
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: