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

ApiUserController::destroy()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 3
nc 1
nop 1
dl 0
loc 6
rs 9.4285
c 1
b 0
f 0
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