Skip to content
This repository was archived by the owner on Nov 26, 2024. It is now read-only.

Commit b33bc0f

Browse files
committed
Done update user
1 parent 890a933 commit b33bc0f

File tree

4 files changed

+40
-3
lines changed

4 files changed

+40
-3
lines changed

app/Http/Controllers/Api/Manage/UserController.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,24 @@ public function show($id)
7676
*/
7777
public function update(Request $request, $id)
7878
{
79+
$this->validate($request, [
80+
'name' => 'required|string|max:255',
81+
]);
82+
83+
$fields = $request->only('name');
84+
85+
if(!empty($request->input('password'))) {
86+
$this->validate($request, [
87+
'password' => 'required|string|min:6|confirmed',
88+
]);
89+
$fields['password'] = bcrypt($request->input('password'));
90+
}
91+
92+
$user = User::findByHashSlug($id);
93+
$user->update($fields);
94+
$user->syncRoles($request->input('roles'));
95+
96+
return response()->api([], __('User successfully updated.'), true, 201);
7997
}
8098

8199
/**

resources/views/manage/users/index.blade.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,11 @@
2020
'updated_at' => __('table.updated_at')
2121
],
2222
'forms' => [
23-
'create' => 'create-user-form',
24-
'edit' => 'edit-user-form',
23+
'create' => 'user-form',
24+
'edit' => 'user-form',
25+
],
26+
'disabled' => [
27+
'email'
2528
]
2629
])
2730
@include('manage.users.partials.modals.form')

resources/views/manage/users/partials/forms/create.blade.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
@include('components.forms.hidden', [
2+
'id' => 'id',
3+
'name' => 'id',
4+
'value' => ''
5+
])
6+
17
@include('components.forms.input', [
28
'input_label' => 'Name',
39
])

resources/views/manage/users/partials/scripts.blade.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
var routes = @json($routes);
77
var columns = @json($columns);
88
var forms = @json($forms);
9+
var disabled = @json($disabled);
910
jQuery(document).ready(function($) {
1011
/* Initialisation */
1112
$('.select2').select2();
@@ -15,7 +16,8 @@
1516
event.preventDefault();
1617
/* Can be refactor to determine to use post or put */
1718
if($("[name='_method']").val() == 'PUT') {
18-
axios.put(route(routes.store), $('#' + forms.create).serialize())
19+
var id = $("[name='id']").val();
20+
axios.put(route(routes.update, id), $('#' + forms.create).serialize())
1921
.then(response => {
2022
$(table_id).DataTable().ajax.reload();
2123
swal('{!! __('User') !!}', response.data.message, 'success');
@@ -43,6 +45,10 @@
4345
$("[name='_method']").val('POST');
4446
/* Handle primary key */
4547
$("[name='id']").val(null);
48+
/* Enable disabled inputs defined */
49+
$.each(disabled, function(index, val) {
50+
$("[name='" + val + "']").prop('readonly', false);
51+
});
4652
$('#user-modal').modal('show');
4753
});
4854
@@ -74,6 +80,10 @@
7480
$("[name='_method']").val('PUT');
7581
/* Handle primary key */
7682
$("[name='id']").val(id);
83+
/* Disable inputs defined */
84+
$.each(disabled, function(index, val) {
85+
$("[name='" + val + "']").prop('readonly', true);
86+
});
7787
var data = response.data.data;
7888
$.each(columns, function(index, val) {
7989
if(data[index] != null) {

0 commit comments

Comments
 (0)