Completed
Push — master ( fe4c38...cc65b4 )
by Eric
06:25
created

ApiUserController   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

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

5 Methods

Rating   Name   Duplication   Size   Complexity  
A index() 0 4 1
A store() 0 16 1
A destroy() 0 6 1
A update() 0 10 1
A show() 0 4 1
1
<?php
2
3
namespace Ergare17\Articles\Http\Controllers;
4
use App\User;
5
use Illuminate\Http\Request;
6
7
class ApiUserController extends Controller
8
{
9
    public function index()
10
    {
11
        return User::all();
12
    }
13
14
    // Injeccció de depèndències
15
    public function store(Request $request)
16
    {
17
        $request->validate([
18
            'name'     => 'required',
19
            'email'    => 'required',
20
            'password' => 'required',
21
        ]);
22
23
        $user = User::create([
24
            'name'     => $request->name,
25
            'email'    => $request->email,
26
            'password' => $request->password,
27
        ]);
28
29
        return $user;
30
    }
31
32
    public function destroy(User $user)
33
    {
34
        $user->delete();
35
36
        return $user;
37
    }
38
39
    public function update(Request $request, User $user)
40
    {
41
        $request->validate([
42
            'name' => 'required',
43
        ]);
44
        $user->name = $request->name;
45
        $user->save();
46
47
        return $user;
48
    }
49
50
    public function show(User $user)
51
    {
52
        return $user;
53
    }
54
}
55