Completed
Push — master ( b8fc4b...08375c )
by Mohamed
10:19
created

UserController::destroy()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
1
<?php
2
3
namespace Microboard\Http\Controllers;
4
5
use Illuminate\Auth\Access\AuthorizationException;
6
use Microboard\Http\Requests\UpdateUserFormRequest;
7
use Microboard\Http\Requests\StoreUserFormRequest;
8
use Microboard\DataTables\UserDataTable;
9
use Illuminate\Http\RedirectResponse;
10
use Illuminate\Http\Response;
11
use Illuminate\View\View;
12
use Exception;
13
use App\User;
14
15
class UserController extends Controller
16
{
17
    /**
18
     * Display a listing of the resource.
19
     *
20
     * @param UserDataTable $table
21
     * @return Response
22
     * @throws AuthorizationException
23
     */
24
    public function index(UserDataTable $table)
25
    {
26
        $this->authorize('viewAny', new User);
27
        return $table->render('microboard::resource.index');
28
    }
29
30
    /**
31
     * Show the form for creating a new resource.
32
     *
33
     * @return View
34
     * @throws AuthorizationException
35
     */
36
    public function create()
37
    {
38
        $this->authorize('create', new User);
39
        return view('microboard::resource.create');
40
    }
41
42
    /**
43
     * Store a newly created resource in storage.
44
     *
45
     * @param StoreUserFormRequest $request
46
     * @return RedirectResponse
47
     * @throws AuthorizationException
48
     */
49
    public function store(StoreUserFormRequest $request)
50
    {
51
        $this->authorize('create', new User);
52
        $user = User::create($request->validated());
53
        return redirect()->route('microboard.users.show', $user);
54
    }
55
56
    /**
57
     * Display the specified resource.
58
     *
59
     * @param User $user
60
     * @return View
61
     * @throws AuthorizationException
62
     */
63
    public function show(User $user)
64
    {
65
        $this->authorize('view', $user);
66
        return view('microboard::resource.view', compact('user'));
67
    }
68
69
    /**
70
     * Show the form for editing the specified resource.
71
     *
72
     * @param User $user
73
     * @return View
74
     * @throws AuthorizationException
75
     */
76
    public function edit(User $user)
77
    {
78
        $this->authorize('update', $user);
79
        return view('microboard::resource.edit', compact('user'));
80
    }
81
82
    /**
83
     * Update the specified resource in storage.
84
     *
85
     * @param UpdateUserFormRequest $request
86
     * @param User $user
87
     * @return RedirectResponse
88
     * @throws AuthorizationException
89
     */
90
    public function update(UpdateUserFormRequest $request, User $user)
91
    {
92
        $this->authorize('update', $user);
93
        $user->update($request->validated());
94
        return redirect()->route('microboard.users.show', $user);
95
    }
96
97
    /**
98
     * Remove the specified resource from storage.
99
     *
100
     * @param User $user
101
     * @return RedirectResponse
102
     * @throws AuthorizationException
103
     * @throws Exception
104
     */
105
    public function destroy(User $user)
106
    {
107
        $this->authorize('update', $user);
108
        $user->delete();
109
        return redirect()->route('microboard.users.index');
110
    }
111
}
112