Skip to content

Commit

Permalink
users fixup when update user, some UI improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
alfredobarron committed Oct 23, 2018
1 parent 9b77904 commit f094c27
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 13 deletions.
20 changes: 13 additions & 7 deletions app/Http/Controllers/Users/UserController.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,18 +58,24 @@ public function update (Request $request)
$this->validate($request, [
'name' => 'required|string',
'email' => 'required|email|unique:users,email,'.$request->id,
'password' => 'string'
'password' => 'string|nullable'
]);

$user = User::find($request->id);

$user->name = $request->name;
$user->email = $request->email;
$user->password = Hash::make($request->password);
$user->save();
if ($user->name != $request->name) {
$avatar = Avatar::create($request->name)->getImageObject()->encode('png');
Storage::put('avatars/'.$user->id.'/avatar.png', (string) $avatar);
$user->name = $request->name;
}
if ($user->email != $request->email) {
$user->email = $request->email;
}
if ($request->password != '') {
$user->password = Hash::make($request->password);
}

$avatar = Avatar::create($user->name)->getImageObject()->encode('png');
Storage::put('avatars/'.$user->id.'/avatar.png', (string) $avatar);
$user->save();

return $user;
}
Expand Down
12 changes: 9 additions & 3 deletions resources/js/components/user/Create.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@
<div class="card">
<div class="card-header">
<i class="fas fa-plus"></i> New User
<button class="btn btn-primary float-right" type="button" :disabled="submiting" @click="create" >
<i class="fas fa-spinner fa-spin" v-if="submiting"></i> Save
</button>
</div>
<div class="card-body">
<form class="form-horizontal">
Expand All @@ -31,6 +28,15 @@
</div>
</form>
</div>
<div class="card-footer">
<div class="form-group row">
<div class="col-md-9 offset-md-3">
<button class="btn btn-primary float-right" type="button" :disabled="submiting" @click="create" >
<i class="fas fa-spinner fa-spin" v-if="submiting"></i> Save
</button>
</div>
</div>
</div>
</div>
</template>

Expand Down
12 changes: 9 additions & 3 deletions resources/js/components/user/Edit.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@
<div class="card">
<div class="card-header">
<i class="fas fa-pencil-alt"></i> Edit User
<button class="btn btn-primary float-right" type="button" :disabled="submiting" @click="update" >
<i class="fas fa-spinner fa-spin" v-if="submiting"></i> Save
</button>
</div>
<div class="card-body">
<form class="form-horizontal">
Expand Down Expand Up @@ -51,6 +48,15 @@
</div>
</form>
</div>
<div class="card-footer">
<div class="form-group row">
<div class="col-md-9 offset-md-3">
<button class="btn btn-primary float-right" type="button" :disabled="submiting" @click="update" >
<i class="fas fa-spinner fa-spin" v-if="submiting"></i> Save
</button>
</div>
</div>
</div>
</div>
</template>

Expand Down

0 comments on commit f094c27

Please sign in to comment.