Passed
Push — dev5 ( 9ca56e...5adb95 )
by Ron
08:24
created

DashboardController::getNotifications()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 1
c 0
b 0
f 0
nc 1
nop 0
dl 0
loc 3
ccs 0
cts 2
cp 0
crap 2
rs 10
1
<?php
2
3
namespace App\Http\Controllers;
4
5
use Illuminate\Support\Facades\Auth;
6
7
use App\Domains\Users\GetUserStats;
8
use App\Domains\TechTips\GetTechTipStats;
9
use App\Domains\Users\MarkUserNotifications;
10
11
class DashboardController extends Controller
12
{
13 20
    public function __construct()
14
    {
15
        //  Only authorized users have access to these pages
16 20
        $this->middleware('auth');
17 20
    }
18
19
    //  Dashboard is the Logged In User home landing page
20 2
    public function index()
21
    {
22 2
        $userStats = new GetUserStats;
23 2
        $tipStats  = new GetTechTipStats;
24
25 2
        return view('dashboard', [
26 2
            'custFavs'    => $userStats->getUserCustomerFavs(),
27 2
            'tipFavs'     => $userStats->getUserTechTipFavs(),
28 2
            'tips30'      => $tipStats->getTipsInLastDays(30),
29 2
            'tipsAll'     => $tipStats->getTotalTechTipCount(),
30 2
            'activeLinks' => $userStats->getUserActiveFileLinks(),
31 2
            'totalLinks'  => $userStats->getUserTotalLinks(),
32
        ]);
33
    }
34
35
    //  Get the users notifications
36
    public function getNotifications()
37
    {
38
        return Auth::user()->notifications;
39
    }
40
41
    //  Mark a notification as read
42 4
    public function markNotification($id)
43
    {
44 4
        (new MarkUserNotifications)->markNotificationRead($id);
45
46
        return response()->json(['success' => true]);
47
    }
48
49
    //  Delte a user notification
50 4
    public function delNotification($id)
51
    {
52 4
        (new MarkUserNotifications)->deleteNotification($id);
53
54
        return response()->json(['success' => true]);
55
    }
56
57
    //  About page
58
    public function about()
59
    {
60
        return view('about', ['branch' => 'latest']);
61
    }
62
}
63