Completed
Push — master ( f2f6fa...1beb9c )
by claudio
03:43
created

EmployeesController::store()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 8
ccs 5
cts 5
cp 1
rs 9.4286
cc 1
eloc 5
nc 1
nop 1
crap 1
1
<?php
2
3
namespace plunner\Http\Controllers\Companies\Employees;
4
5
use Illuminate\Http\Request;
6
use plunner\Company;
7
use plunner\Employee;
8
use plunner\Http\Controllers\Controller;
9
use plunner\Http\Requests\Companies\EmployeeRequest;
10
11
12
class EmployeesController extends Controller
13
{
14
    /**
15
     * @var \plunner\Company
16
     */
17
    private $user;
0 ignored issues
show
Unused Code introduced by
The property $user is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
18
19
    /**
20
     * ExampleController constructor.
21
     */
22 8
    public function __construct()
23
    {
24 8
        config(['auth.model' => \plunner\Company::class]);
25 8
        config(['jwt.user' => \plunner\Company::class]);
26 8
        $this->middleware('jwt.authandrefresh:mode-cn');
27 8
    }
28
29
30
    /**
31
     * Display a listing of the resource.
32
     *
33
     * @return \Illuminate\Http\Response
34
     */
35 1
    public function index()
36
    {
37
        //
38
        /**
39
         * @var $company Company
40
         */
41 1
        $company = \Auth::user();
42 1
        return $company->employees;
43
    }
44
45
    /**
46
     * Store a newly created resource in storage.
47
     *
48
     * @param  EmployeeRequest  $request
49
     * @return \Illuminate\Http\Response
50
     */
51 2
    public function store(EmployeeRequest $request)
52
    {
53
        //
54 2
        $company = \Auth::user();
55 2
        $input = $request->all();
56 2
        $employee = $company->employees()->create($input);
57 2
        return $employee;
58
    }
59
60
    /**
61
     * Display the specified resource.
62
     *
63
     * @param  int  $id
64
     * @return \Illuminate\Http\Response
65
     */
66 2
    public function show($id)
67
    {
68
        //
69 2
        $employee = Employee::findOrFail($id);
1 ignored issue
show
Documentation introduced by
The method findOrFail does not exist on object<plunner\Employee>? Since you implemented __callStatic, maybe consider adding a @method annotation.
Loading history...
70 2
        $this->authorize($employee);
71 2
        return $employee;
72
    }
73
74
    /**
75
     * Update the specified resource in storage.
76
     *
77
     * @param  EmployeeRequest  $request
78
     * @param  int  $id
79
     * @return \Illuminate\Http\Response
80
     */
81 1
    public function update(EmployeeRequest $request, $id)
82
    {
83
        //
84 1
        $employee = Employee::findOrFail($id);
1 ignored issue
show
Documentation introduced by
The method findOrFail does not exist on object<plunner\Employee>? Since you implemented __callStatic, maybe consider adding a @method annotation.
Loading history...
85 1
        $this->authorize($employee);
86 1
        $input = $request->all();
87 1
        $employee->update($input);
88 1
        return $employee;
89
    }
90
91
    /**
92
     * Remove the specified resource from storage.
93
     *
94
     * @param  int  $id
95
     * @return \Illuminate\Http\Response
96
     */
97 2
    public function destroy($id)
98
    {
99
        //
100 2
        $employee = Employee::findOrFail($id);
1 ignored issue
show
Documentation introduced by
The method findOrFail does not exist on object<plunner\Employee>? Since you implemented __callStatic, maybe consider adding a @method annotation.
Loading history...
101 2
        $this->authorize($employee);
102 1
        $employee->delete();
103 1
        return $employee;
104
    }
105
}
106