NotificationsController   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 5

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A index() 0 5 1
A read() 0 17 4
1
<?php
2
3
namespace Hechoenlaravel\JarvisFoundation\Http\Controllers;
4
5
use Auth;
6
use Carbon\Carbon;
7
use Hechoenlaravel\JarvisFoundation\Notifications\SendAppNotification\Notification;
8
use Hechoenlaravel\JarvisFoundation\Notifications\SendAppNotification\Events\NotificationWasReaded;
9
use Hechoenlaravel\JarvisFoundation\Notifications\SendAppNotification\Events\NotificationWasOpened;
10
11
/**
12
 * Class NotificationsController
13
 * @package Hechoenlaravel\JarvisFoundation\Http\Controllers
14
 */
15
class NotificationsController extends Controller
16
{
17
    /**
18
     * Lists notifications
19
     * @return $this
20
     */
21
    public function index()
22
    {
23
        $notifications = Notification::byUser(Auth::user())->orderBy('created_at', 'DESC')->paginate(20);
24
        return view('jarvisPlatform::notifications.index')->with('notifications', $notifications);
0 ignored issues
show
Bug introduced by
The method with() does not seem to exist on object<BladeView>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
25
    }
26
27
    /**
28
     * Read a notification
29
     * @param $id
30
     * @return \Illuminate\Http\RedirectResponse
31
     */
32
    public function read($id)
33
    {
34
        $notification = Notification::findOrFail($id);
35
        if ($notification->user_id != Auth::user()->id) {
36
            abort(403);
37
        }
38
        if (empty($notification->readed_at)) {
39
            $notification->readed_at = Carbon::now();
40
            $notification->save();
41
            event(new NotificationWasReaded($notification));
42
        }
43
        event(new NotificationWasOpened($notification));
44
        if (!empty($notification->link)) {
45
            return redirect()->to($notification->link);
46
        }
47
        return redirect()->route('notifications.index');
48
    }
49
}
50