Completed
Push — master ( 2f299a...036503 )
by Ron
12:27 queued 05:09
created

DashboardController::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace App\Http\Controllers;
4
5
use Illuminate\Http\Request;
6
use Illuminate\Support\Facades\Auth;
7
use Illuminate\Support\Facades\Log;
8
use App\CustomerFavs;
9
use App\TechTipFavs;
10
11
class DashboardController extends Controller
12
{
13
    public function __construct()
14
    {
15
        $this->middleware('auth');
16
    }
17
18
    //  Dashboard is the Logged In User home landing page
19
    public function index()
20
    {
21
        //  Get the users notifications
22
        $notifications = Auth::user()->unreadNotifications;
23
        
24
        //  Get the users Customer bookmarks
25
        $custFavs = CustomerFavs::where('user_id', Auth::user()->user_id)
26
            ->LeftJoin('customers', 'customer_favs.cust_id', '=', 'customers.cust_id')
27
            ->get();
28
        //  Get the users Tech Tip bookmarks
29
        $tipFavs = TechTipFavs::where('tech_tip_favs.user_id', Auth::user()->user_id)
30
            ->LeftJoin('tech_tips', 'tech_tips.tip_id', '=', 'tech_tip_favs.tip_id')
31
            ->get();
32
        
33
        return view('dashboard', [
34
            'custFavs' => $custFavs,
35
            'tipFavs'  => $tipFavs,
36
            'notifications' => $notifications
37
        ]);
38
    }
39
    
40
    public function markNotification($id)
41
    {
42
        $notification = Auth::user()->notifications()->where('id', $id)->first();
43
        if($notification)
44
        {
45
            $notification->delete();
46
            Log::info('Notification ID-'.$id.' deleted for User ID-'.Auth::user()->user_id);
47
        }
48
        else
49
        {
50
            Log::notice('Notification ID-'.$id.' not found for user ID-'.Auth::user()->user_id);
51
        }
52
    }
53
}
54