Skip to content

Commit 599e6ab

Browse files
Finish update user functionality
1 parent 63cd0d3 commit 599e6ab

File tree

4 files changed

+79
-15
lines changed

4 files changed

+79
-15
lines changed

app/Http/Controllers/UserController.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,9 @@ public function edit(string $id)
6262
*/
6363
public function update(Request $request, string $id)
6464
{
65-
//
65+
User::where('id', $id)->update($request->all());
66+
67+
return redirect('/users')->with('success', 'User has been updated!');
6668
}
6769

6870
/**

resources/js/Pages/Users/Create.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ import Button from '@/Components/Button.vue';
7676
export default {
7777
components: {
7878
AppLayout,
79-
Button
79+
Button,
8080
},
8181
props: {
8282
errors: Object,

resources/js/Pages/Users/Edit.vue

Lines changed: 64 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,76 @@
11
<template>
2-
<div>
3-
<AppLayout title="Edit role">
4-
Edit user: {{ user.name }}
5-
</AppLayout>
6-
</div>
2+
<AppLayout title="Edit user">
3+
4+
<template #header>
5+
<Breadcrumb :href="'users'" :title="'Users'" :property="user" />
6+
</template>
7+
8+
<div class="py-12">
9+
<div class="max-w-7xl mx-auto sm:px-6 lg:px-8">
10+
<div class="m-auto w-full max-w-xs">
11+
<form @submit.prevent="submit" class="bg-white shadow-md rounded px-8 pt-6 pb-8 mb-4">
12+
13+
<div class="mb-4">
14+
<label class="block text-gray-700 text-sm font-bold mb-2" for="name">
15+
Name
16+
</label>
17+
<input v-model="form.name"
18+
class="shadow appearance-none border rounded w-full py-2 px-3 text-gray-700 leading-tight focus:outline-none focus:shadow-outline"
19+
id="name" type="text">
20+
</div>
21+
22+
<div class="mb-4">
23+
<label class="block text-gray-700 text-sm font-bold mb-2" for="email">
24+
E-mail
25+
</label>
26+
<input v-model="form.email"
27+
class="shadow appearance-none border rounded w-full py-2 px-3 text-gray-700 leading-tight focus:outline-none focus:shadow-outline"
28+
id="email" type="email">
29+
</div>
30+
31+
<div class="flex items-center justify-between">
32+
<Button :form="form"></Button>
33+
</div>
34+
</form>
35+
<p class="text-center text-gray-500 text-xs">
36+
&copy;2022 - <a class="text-blue-500" href="https://github.com/perisicnikola37"
37+
target="_blank">@perisicnikola37</a>
38+
</p>
39+
</div>
40+
41+
</div>
42+
</div>
43+
</AppLayout>
744
</template>
845

946
<script>
1047
import AppLayout from '@/Layouts/AppLayout.vue';
48+
import Breadcrumb from "@/Components/Breadcrumb.vue";
49+
import Button from "@/Components/Button.vue";
1150
1251
export default {
52+
components: {
53+
AppLayout,
54+
Breadcrumb,
55+
Button
56+
},
1357
props: {
1458
user: Object,
1559
},
16-
components: { AppLayout }
60+
data() {
61+
return {
62+
form: this.$inertia.form({
63+
name: this.user.name,
64+
email: this.user.email,
65+
})
66+
}
67+
},
68+
methods: {
69+
submit() {
70+
this.form.put(this.route('users.update', this.user.id), {
71+
_token: this.$page.props.csrf_token,
72+
})
73+
}
74+
}
1775
}
1876
</script>

resources/js/Pages/Users/Index.vue

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,9 @@
2222
<div class="mb-3 xl:w-96">
2323
<div class="relative flex items-stretch w-4/5 mb-3 input-group">
2424

25-
<input type="text" v-model="term" @keyup="search">
26-
27-
<!-- <input id="search" type='text' v-model="term" @keyup="search"
25+
<input id="search" type='text' v-model="term" @keyup="search"
2826
class="outline-none focus:ring-0 rounded-r-none form-control relative min-w-0 block w-full px-3 py-1.5 text-base font-normal text-gray-700 bg-white bg-clip-padding border border-solid border-gray-300 rounded transition ease-in-out m-0"
29-
placeholder="Search..."> -->
27+
placeholder="Search...">
3028

3129
<button
3230
class="rounded-l-none btn px-6 py-2.5 bg-blue-600 text-white font-medium text-xs leading-tight uppercase rounded shadow-md hover:bg-blue-700 hover:shadow-lg focus:bg-blue-700 focus:shadow-lg focus:outline-none focus:ring-0 active:bg-blue-800 active:shadow-lg transition duration-150 ease-in-out flex items-center"
@@ -139,9 +137,15 @@ export default {
139137
}
140138
},
141139
methods: {
142-
deleteUser(user) {
143-
if (!confirm('Are you sure you want to delete user?')) return;
144-
this.$inertia.delete(route('users.destroy', user.id));
140+
confirmAction(message, callback) {
141+
if (confirm(message)) {
142+
callback();
143+
}
144+
},
145+
deleteUser: function (user) {
146+
this.confirmAction('Are you sure you want to delete user?', function () {
147+
this.$inertia.delete(route('users.destroy', user.id));
148+
}.bind(this));
145149
},
146150
search() {
147151
this.$inertia.replace(this.route('users.index', { term: this.term }))

0 commit comments

Comments
 (0)