Passed
Push — task/user-api-endpoint ( 6e4649...f0b85b )
by Chris
04:32
created

ManagerController   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 80
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 9
eloc 11
c 0
b 0
f 0
dl 0
loc 80
rs 10

7 Methods

Rating   Name   Duplication   Size   Complexity  
A destroy() 0 2 1
A update() 0 6 1
A store() 0 2 1
A index() 0 2 1
A __construct() 0 4 1
A show() 0 3 1
A showAuthenticated() 0 7 3
1
<?php
2
3
namespace App\Http\Controllers\Api;
4
5
use App\Http\Controllers\Controller;
6
use App\Http\Requests\UpdateManagerApi;
7
use App\Models\Manager;
8
use Illuminate\Http\Request;
9
use Illuminate\Http\Resources\Json\JsonResource;
10
use Illuminate\Support\Facades\Auth;
11
12
class ManagerController extends Controller
13
{
14
    /**
15
     * Class constructor.
16
     */
17
    public function __construct()
18
    {
19
        // This applies the appropriate policy to each resource route.
20
        $this->authorizeResource(Manager::class, 'manager');
21
    }
22
23
    /**
24
     * Display a listing of the resource.
25
     *
26
     * @return \Illuminate\Http\Response
27
     */
28
    public function index()
29
    {
30
        // TODO: complete.
31
    }
32
33
    /**
34
     * Store a newly created resource in storage.
35
     *
36
     * @param  \Illuminate\Http\Request $request Incoming Request.
37
     * @return \Illuminate\Http\Response
38
     */
39
    public function store(Request $request)
40
    {
41
        // TODO: complete.
42
    }
43
44
    /**
45
     * Display the specified resource.
46
     *
47
     * @param  \App\Models\Manager $manager Incoming Manager.
48
     * @return \Illuminate\Http\Response
49
     */
50
    public function show(Manager $manager)
51
    {
52
        return new JsonResource($manager);
53
    }
54
55
    /**
56
     * Display the Manager for the current logged in user.
57
     *
58
     * @return \Illuminate\Http\Response
59
     */
60
    public function showAuthenticated()
61
    {
62
        $user = Auth::user();
63
        if ($user !== null && $user->manager !== null) {
64
            return new JsonResource($user->manager);
65
        }
66
        return response()->json([]);
0 ignored issues
show
Bug introduced by
The function response was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

66
        return /** @scrutinizer ignore-call */ response()->json([]);
Loading history...
67
    }
68
69
    /**
70
     * Update the specified resource in storage.
71
     *
72
     * @param  \App\Http\Requests\UpdateManagerApi $request Incoming Form Request.
73
     * @param  \App\Models\Manager                 $manager Incoming Manager.
74
     * @return \Illuminate\Http\Response
75
     */
76
    public function update(UpdateManagerApi $request, Manager $manager)
77
    {
78
        $validated = $request->validated();
79
        $manager->fill($validated);
80
        $manager->save();
81
        return new JsonResource($manager);
82
    }
83
84
    /**
85
     * Remove the specified resource from storage.
86
     *
87
     * @param  \App\Models\Manager $manager Incoming Manager.
88
     * @return \Illuminate\Http\Response
89
     */
90
    public function destroy(Manager $manager)
91
    {
92
        // TODO: complete.
93
    }
94
}
95