NotificationsController   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 56
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
c 1
b 0
f 0
lcom 1
cbo 3
dl 0
loc 56
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 1
A index() 0 6 1
A destroy() 0 7 1
A destroyAll() 0 7 1
A markAllAsRead() 0 7 1
1
<?php
2
3
namespace Modules\Notification\Http\Controllers\Admin;
4
5
use Modules\Core\Http\Controllers\Admin\AdminBaseController;
6
use Modules\Notification\Entities\Notification;
7
use Modules\Notification\Repositories\NotificationRepository;
8
use Modules\User\Contracts\Authentication;
9
10
class NotificationsController extends AdminBaseController
11
{
12
    /**
13
     * @var NotificationRepository
14
     */
15
    private $notification;
16
    /**
17
     * @var Authentication
18
     */
19
    private $auth;
20
21
    public function __construct(NotificationRepository $notification, Authentication $auth)
22
    {
23
        parent::__construct();
24
25
        $this->notification = $notification;
26
        $this->auth = $auth;
27
    }
28
29
    public function index()
30
    {
31
        $notifications = $this->notification->allForUser($this->auth->id());
32
33
        return view('notification::admin.notifications.index', compact('notifications'));
34
    }
35
36
    /**
37
     * Remove the specified resource from storage.
38
     *
39
     * @param  Notification $notification
40
     * @return Response
41
     */
42
    public function destroy(Notification $notification)
43
    {
44
        $this->notification->destroy($notification);
45
46
        return redirect()->route('admin.notification.notification.index')
47
            ->withSuccess(trans('core::core.messages.resource deleted', ['name' => 'Notification']));
48
    }
49
50
    public function destroyAll()
51
    {
52
        $this->notification->deleteAllForUser($this->auth->id());
53
54
        return redirect()->route('admin.notification.notification.index')
55
            ->withSuccess(trans('notification::messages.all notifications deleted'));
56
    }
57
58
    public function markAllAsRead()
59
    {
60
        $this->notification->markAllAsReadForUser($this->auth->id());
61
62
        return redirect()->route('admin.notification.notification.index')
63
            ->withSuccess(trans('notification::messages.all notifications marked as read'));
64
    }
65
}
66