Completed
Branch dev4 (91d39d)
by Ron
09:48
created

DashboardController::markNotification()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 11
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 6
nc 2
nop 1
dl 0
loc 11
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;
1 ignored issue
show
Bug introduced by
The property unreadNotifications does not seem to exist on App\User. Are you sure there is no database migration missing?

Checks if undeclared accessed properties appear in database migrations and if the creating migration is correct.

Loading history...
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