Completed
Push — device_ip ( 1d928b...ddfcff )
by Tony
03:21 queued 11s
created

NotificationController::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 0
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
    {
18
        $this->middleware('auth');
19
    }
20
21
    /**
22
     * Display a listing of the resource.
23
     *
24
     * @param null $type
25
     * @return \Illuminate\Http\Response
26
     */
27
    public function index($type = null)
28
    {
29
30
        $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...
31
        if ($type === 'archive') {
32
            $page = '';
33
            $button = 'Notifications';
34
            $bg = 'maroon';
35
        }
36
        else {
37
            $page = 'archive';
38
            $button = 'Archive';
39
            $bg = 'blue';
40
        }
41
42
        return view('notifications.list', compact(['notifications', 'page', 'button', 'bg', "type"]));
43
    }
44
45
    /**
46
     * Update a notifications status.
47
     *
48
     * @param $id
49
     * @param $action
50
     * @return \Illuminate\Http\JsonResponse
51
     */
52
    public function update($id, $action)
53
    {
54
        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...
55
    }
56
57
    /**
58
     * Create a new notification
59
     *
60
     * @param Request $request
61
     * @return \Illuminate\Http\JsonResponse
62
     */
63
    public function create(Request $request)
64
    {
65
        $this->validate($request, [
66
            'title' => 'required|unique:notifications|max:255',
67
            'body'  => 'required',
68
        ]);
69
        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...
70
    }
71
72
}
73