1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* NOTICE OF LICENSE |
5
|
|
|
* |
6
|
|
|
* Part of the Rinvex Fort Package. |
7
|
|
|
* |
8
|
|
|
* This source file is subject to The MIT License (MIT) |
9
|
|
|
* that is bundled with this package in the LICENSE file. |
10
|
|
|
* |
11
|
|
|
* Package: Rinvex Fort Package |
12
|
|
|
* License: The MIT License (MIT) |
13
|
|
|
* Link: https://rinvex.com |
14
|
|
|
*/ |
15
|
|
|
|
16
|
|
|
namespace Rinvex\Fort\Http\Controllers\Backend; |
17
|
|
|
|
18
|
|
|
use Rinvex\Country\Loader; |
19
|
|
|
use Illuminate\Http\Request; |
20
|
|
|
use Rinvex\Fort\Models\User; |
21
|
|
|
use Rinvex\Fort\Contracts\UserRepositoryContract; |
22
|
|
|
use Rinvex\Fort\Http\Controllers\AuthorizedController; |
23
|
|
|
|
24
|
|
|
class UsersController extends AuthorizedController |
25
|
|
|
{ |
26
|
|
|
/** |
27
|
|
|
* {@inheritdoc} |
28
|
|
|
*/ |
29
|
|
|
protected $resourceAbilityMap = [ |
30
|
|
|
'activate' => 'activate', |
31
|
|
|
'deactivate' => 'deactivate', |
32
|
|
|
]; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* The user repository instance. |
36
|
|
|
* |
37
|
|
|
* @var \Rinvex\Fort\Contracts\UserRepositoryContract |
38
|
|
|
*/ |
39
|
|
|
protected $userRepository; |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* Create a new users controller instance. |
43
|
|
|
* |
44
|
|
|
* @return void |
|
|
|
|
45
|
|
|
*/ |
46
|
|
|
public function __construct(UserRepositoryContract $userRepository) |
47
|
|
|
{ |
48
|
|
|
parent::__construct(); |
49
|
|
|
|
50
|
|
|
$this->authorizeResource(User::class); |
51
|
|
|
|
52
|
|
|
$this->userRepository = $userRepository; |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* Display a listing of the resource. |
57
|
|
|
* |
58
|
|
|
* @return \Illuminate\Http\Response |
|
|
|
|
59
|
|
|
*/ |
60
|
|
|
public function index() |
61
|
|
|
{ |
62
|
|
|
$users = $this->userRepository->paginate(config('rinvex.fort.backend.items_per_page')); |
63
|
|
|
|
64
|
|
|
return view('rinvex.fort::backend.users.index', compact('users')); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* Display the specified resource. |
69
|
|
|
* |
70
|
|
|
* @param int $id |
71
|
|
|
* |
72
|
|
|
* @return \Illuminate\Http\Response|\Illuminate\Http\JsonResponse|\Illuminate\Http\RedirectResponse |
|
|
|
|
73
|
|
|
*/ |
74
|
|
|
public function show($id) |
75
|
|
|
{ |
76
|
|
|
if (! $user = $this->userRepository->find($id)) { |
77
|
|
|
return intend([ |
78
|
|
|
'intended' => route('rinvex.fort.backend.users.index'), |
79
|
|
|
'withErrors' => ['rinvex.fort.user.not_found' => trans('rinvex.fort::backend/messages.user.not_found', ['user' => $id])], |
|
|
|
|
80
|
|
|
]); |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
$actions = ['view', 'create', 'edit', 'delete', 'import', 'export']; |
84
|
|
|
$resources = app('rinvex.fort.ability')->findAll()->groupBy('resource'); |
85
|
|
|
$columns = ['resource', 'view', 'create', 'edit', 'delete', 'import', 'export', 'other']; |
86
|
|
|
$userCountry = Loader::country($user->country); |
87
|
|
|
$country = ! empty($userCountry) ? $userCountry->getName().' '.$userCountry->getEmoji() : null; |
88
|
|
|
$phone = ! empty($userCountry) ? $userCountry->getCallingCode().$user->phone : null; |
89
|
|
|
|
90
|
|
|
return view('rinvex.fort::backend.users.show', compact('user', 'resources', 'actions', 'columns', 'country', 'phone')); |
|
|
|
|
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
/** |
94
|
|
|
* Bulk control the given resources. |
95
|
|
|
* |
96
|
|
|
* @return \Illuminate\Http\Response |
|
|
|
|
97
|
|
|
*/ |
98
|
|
|
public function bulk() |
99
|
|
|
{ |
100
|
|
|
// |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
/** |
104
|
|
|
* Show the form for creating a new resource. |
105
|
|
|
* |
106
|
|
|
* @return \Illuminate\Http\Response |
|
|
|
|
107
|
|
|
*/ |
108
|
|
|
public function create() |
109
|
|
|
{ |
110
|
|
|
return $this->form('create', 'store'); |
111
|
|
|
} |
112
|
|
|
|
113
|
|
|
/** |
114
|
|
|
* Show the form for copying the given resource. |
115
|
|
|
* |
116
|
|
|
* @param int $id |
117
|
|
|
* |
118
|
|
|
* @return \Illuminate\Http\Response |
|
|
|
|
119
|
|
|
*/ |
120
|
|
|
public function copy($id) |
121
|
|
|
{ |
122
|
|
|
return $this->form('copy', 'store', $id); |
123
|
|
|
} |
124
|
|
|
|
125
|
|
|
/** |
126
|
|
|
* Show the form for editing the given resource. |
127
|
|
|
* |
128
|
|
|
* @param int $id |
129
|
|
|
* |
130
|
|
|
* @return \Illuminate\Http\Response |
|
|
|
|
131
|
|
|
*/ |
132
|
|
|
public function edit($id) |
133
|
|
|
{ |
134
|
|
|
return $this->form('edit', 'update', $id); |
135
|
|
|
} |
136
|
|
|
|
137
|
|
|
/** |
138
|
|
|
* Show the form for create/edit/copy of the given resource. |
139
|
|
|
* |
140
|
|
|
* @param string $mode |
141
|
|
|
* @param string $action |
142
|
|
|
* @param int|null $id |
143
|
|
|
* |
144
|
|
|
* @return \Illuminate\Http\Response |
|
|
|
|
145
|
|
|
*/ |
146
|
|
|
protected function form($mode, $action, $id = null) |
147
|
|
|
{ |
148
|
|
|
if (! $user = $this->userRepository->getModelInstance($id)) { |
|
|
|
|
149
|
|
|
return intend([ |
150
|
|
|
'intended' => route('rinvex.fort.backend.users.index'), |
151
|
|
|
'withErrors' => ['rinvex.fort.user.not_found' => trans('rinvex.fort::backend/messages.user.not_found', ['user' => $id])], |
|
|
|
|
152
|
|
|
]); |
153
|
|
|
} |
154
|
|
|
|
155
|
|
|
$countries = Loader::countries(); |
156
|
|
|
$resources = app('rinvex.fort.ability')->findAll()->groupBy('resource'); |
157
|
|
|
|
158
|
|
|
return view('rinvex.fort::backend.users.form', compact('user', 'resources', 'countries', 'mode', 'action')); |
159
|
|
|
} |
160
|
|
|
|
161
|
|
|
/** |
162
|
|
|
* Store a newly created resource in storage. |
163
|
|
|
* |
164
|
|
|
* @param \Illuminate\Http\Request $request |
165
|
|
|
* |
166
|
|
|
* @return \Illuminate\Http\Response |
|
|
|
|
167
|
|
|
*/ |
168
|
|
|
public function store(Request $request) |
|
|
|
|
169
|
|
|
{ |
170
|
|
|
// |
171
|
|
|
} |
172
|
|
|
|
173
|
|
|
/** |
174
|
|
|
* Update the given resource in storage. |
175
|
|
|
* |
176
|
|
|
* @param \Illuminate\Http\Request $request |
177
|
|
|
* @param int $id |
178
|
|
|
* |
179
|
|
|
* @return \Illuminate\Http\Response |
|
|
|
|
180
|
|
|
*/ |
181
|
|
|
public function update(Request $request, $id) |
|
|
|
|
182
|
|
|
{ |
183
|
|
|
// |
184
|
|
|
} |
185
|
|
|
|
186
|
|
|
/** |
187
|
|
|
* Delete the given resource from storage. |
188
|
|
|
* |
189
|
|
|
* @param int $id |
190
|
|
|
* |
191
|
|
|
* @return \Illuminate\Http\Response |
|
|
|
|
192
|
|
|
*/ |
193
|
|
|
public function delete($id) |
|
|
|
|
194
|
|
|
{ |
195
|
|
|
// |
196
|
|
|
} |
197
|
|
|
|
198
|
|
|
/** |
199
|
|
|
* Import the given resources into storage. |
200
|
|
|
* |
201
|
|
|
* @return \Illuminate\Http\Response |
|
|
|
|
202
|
|
|
*/ |
203
|
|
|
public function import() |
204
|
|
|
{ |
205
|
|
|
// |
206
|
|
|
} |
207
|
|
|
|
208
|
|
|
/** |
209
|
|
|
* Export the given resources from storage. |
210
|
|
|
* |
211
|
|
|
* @return \Illuminate\Http\Response |
|
|
|
|
212
|
|
|
*/ |
213
|
|
|
public function export() |
214
|
|
|
{ |
215
|
|
|
// |
216
|
|
|
} |
217
|
|
|
} |
218
|
|
|
|
Adding a
@return
annotation to a constructor is not recommended, since a constructor does not have a meaningful return value.Please refer to the PHP core documentation on constructors.