Completed
Pull Request — develop (#48)
by Neil
07:33
created

NotificationController::index()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 18
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 4
Bugs 0 Features 2
Metric Value
c 4
b 0
f 2
dl 0
loc 18
rs 9.4285
cc 2
eloc 11
nc 2
nop 1
1
<?php
2
3
namespace App\Http\Controllers;
4
5
use Dingo\Api\Http;
6
use Dingo\Api\Routing\Helpers;
7
use Illuminate\Http\Request;
8
9
class NotificationController extends Controller
10
{
11
    use Helpers;
12
13
    /**
14
     * Constructor
15
     */
16
    public function __construct() {
17
        $this->middleware('auth');
18
    }
19
20
    /**
21
     * Display a listing of the resource.
22
     *
23
     * @return \Illuminate\Http\Response
24
     */
25
    public function index($type = null)
26
    {
27
28
        $notifications = $this->api->be(auth()->user())->get('/api/notifications/'.$type);
0 ignored issues
show
Bug introduced by
The method user() does not seem to exist on object<Illuminate\Contracts\Auth\Factory>.

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...
29
        if ($type === 'archive')
30
        {
31
            $page   = '';
32
            $button = 'Notifications';
33
            $bg     = 'maroon';
34
        }
35
        else {
36
            $page   = 'archive';
37
            $button = 'Archive';
38
            $bg     = 'blue';
39
        }
40
41
        return view('notifications.list', ['notifications' => $notifications, 'page' => $page, 'button' => $button, 'bg' => $bg, "type" => $type]);
42
    }
43
44
    /**
45
     * Update a notifications status.
46
     *
47
     * @return \Illuminate\Http\Response
48
     */
49
    public function update($id, $action)
50
    {
51
52
        return response()->json($this->api->be(auth()->user())->patch('/api/notifications/'.$id.'/'.$action));
0 ignored issues
show
Bug introduced by
The method user() does not seem to exist on object<Illuminate\Contracts\Auth\Factory>.

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...
53
    }
54
55
    /**
56
     * Create a new notification
57
     *
58
     * @return \Illuminate\Http\Response
59
     */
60
    public function create(Request $request)
61
    {
62
        $this->validate($request, [
63
            'title' => 'required|unique:notifications|max:255',
64
            'body' => 'required',
65
        ]);
66
        return response()->json($this->api->be(auth()->user())->put('/api/notifications', ['title' => $request->title, 'body' => $request->body]));
0 ignored issues
show
Bug introduced by
The method user() does not seem to exist on object<Illuminate\Contracts\Auth\Factory>.

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...
67
    }
68
69
}
70