Completed
Push — development ( b0c738...8cbb83 )
by Kyle
03:47
created

UserController::edit()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
cc 2
eloc 4
nc 2
nop 1
dl 0
loc 9
ccs 0
cts 5
cp 0
crap 6
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace App\Http\Controllers\Admin;
4
5
use App\Http\Controllers\Controller;
6
use App\Http\Requests\CreateUserRequest;
7
use App\Http\Requests\UpdateUserRequest;
8
use App\Services\UserServicesInterface;
9
use Illuminate\Http\Request;
10
11
class UserController extends Controller
12
{
13
    /**
14
     * @var \App\Services\BaseCrudServicesInterface
15
     */
16
    protected $userServices;
17
18
    /**
19
     * Create a new controller instance.
20
     *
21
     * @param UserServicesInterface $userServices
22
     */
23
    public function __construct(UserServicesInterface $userServices)
24
    {
25
        $this->userServices = $userServices;
26
    }
27
28
    /**
29
     * Display a listing of the resource.
30
     *
31
     * @param Request $request
32
     * @return \Illuminate\Http\Response
33
     */
34
    public function index(Request $request)
35
    {
36
        $listData = $this->userServices->getPaginateWithFilter($request->all());
37
        return view('admin.users.index', compact('listData', 'request'));
0 ignored issues
show
Bug Best Practice introduced by
The expression return view('admin.users...'listData', 'request')) returns the type Illuminate\View\View which is incompatible with the documented return type Illuminate\Http\Response.
Loading history...
38
    }
39
40
    /**
41
     * Show the form for creating a new resource.
42
     *
43
     * @return \Illuminate\Http\Response
44
     */
45
    public function create()
46
    {
47
        return view('admin.users.create');
0 ignored issues
show
Bug Best Practice introduced by
The expression return view('admin.users.create') returns the type Illuminate\View\View which is incompatible with the documented return type Illuminate\Http\Response.
Loading history...
48
    }
49
50
    /**
51
     * Store a newly created resource in storage.
52
     *
53
     * @param CreateUserRequest|Request $request
54
     * @return \Illuminate\Http\Response
55
     */
56
    public function store(CreateUserRequest $request)
57
    {
58
        $this->userServices->create($request->validated());
59
60
        return redirect()->route('admin.users.index')
0 ignored issues
show
Bug Best Practice introduced by
The expression return redirect()->route...sages.create_success')) also could return the type Illuminate\Http\RedirectResponse which is incompatible with the documented return type Illuminate\Http\Response.
Loading history...
61
            ->withSuccess(trans('messages.create_success'));
62
    }
63
64
    /**
65
     * Display the specified resource.
66
     *
67
     * @param  int  $id
68
     * @return \Illuminate\Http\Response
69
     */
70
    public function show($id)
71
    {
72
        $user = $this->userServices->read($id);
73
74
        if (empty($user)) {
75
            abort(404);
76
        }
77
78
        return view('admin.users.show', compact('user'));
0 ignored issues
show
Bug Best Practice introduced by
The expression return view('admin.users.show', compact('user')) returns the type Illuminate\View\View which is incompatible with the documented return type Illuminate\Http\Response.
Loading history...
79
    }
80
81
    /**
82
     * Show the form for editing the specified resource.
83
     *
84
     * @param  int  $id
85
     * @return \Illuminate\Http\Response
86
     */
87
    public function edit($id)
88
    {
89
        $user = $this->userServices->read($id);
90
91
        if (empty($user)) {
92
            abort(404);
93
        }
94
95
        return view('admin.users.edit', compact('user'));
0 ignored issues
show
Bug Best Practice introduced by
The expression return view('admin.users.edit', compact('user')) returns the type Illuminate\View\View which is incompatible with the documented return type Illuminate\Http\Response.
Loading history...
96
    }
97
98
    /**
99
     * Update the specified resource in storage.
100
     *
101
     * @param UpdateUserRequest|Request $request
102
     * @param  int $id
103
     * @return \Illuminate\Http\Response
104
     */
105
    public function update(UpdateUserRequest $request, $id)
106
    {
107
        $this->userServices->update($request->validated(), $id);
108
        return redirect()->route('admin.users.index')
0 ignored issues
show
Bug Best Practice introduced by
The expression return redirect()->route...sages.update_success')) also could return the type Illuminate\Http\RedirectResponse which is incompatible with the documented return type Illuminate\Http\Response.
Loading history...
109
            ->withSuccess(trans('messages.update_success'));
110
    }
111
112
    /**
113
     * Remove the specified resource from storage.
114
     *
115
     * @param  int  $id
116
     * @return \Illuminate\Http\Response
117
     */
118
    public function destroy($id)
119
    {
120
        $this->userServices->delete($id);
121
        return redirect()->route('admin.users.index')
0 ignored issues
show
Bug Best Practice introduced by
The expression return redirect()->route...sages.delete_success')) also could return the type Illuminate\Http\RedirectResponse which is incompatible with the documented return type Illuminate\Http\Response.
Loading history...
122
            ->withSuccess(trans('messages.delete_success'));
123
    }
124
}
125