Skip to content

Commit bff7be0

Browse files
Finish user delete function
1 parent f17f969 commit bff7be0

File tree

4 files changed

+20
-8
lines changed

4 files changed

+20
-8
lines changed

app/Http/Controllers/UserController.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@ public function update(Request $request, string $id)
6363
*/
6464
public function destroy(string $id)
6565
{
66-
//
66+
User::destroy($id);
67+
68+
return back();
6769
}
68-
}
70+
}

app/Models/User.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,10 @@ class User extends Authenticatable
5656
*
5757
* @var array<int, string>
5858
*/
59-
// protected $appends = [
60-
// 'profile_photo_url',
61-
// ];
59+
protected $appends = [
60+
'profile_photo_url',
61+
'formatted_created_at'
62+
];
6263

6364
public function getFormattedCreatedAtAttribute()
6465
{

resources/js/Pages/Roles/Index.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@
6666
<tr v-for="role in roles" :key="role.id">
6767
<td class="px-6 py-4 whitespace-nowrap">
6868
<div class="flex items-center justify-center">
69-
<div class="ml-4">
69+
<div>
7070
<div class="text-sm font-medium text-gray-900">
7171
{{ role.id }}
7272
</div>

resources/js/Pages/Users/Index.vue

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,18 +65,21 @@
6565
</td>
6666
<td class="px-6 py-4 whitespace-nowrap">
6767
<div class="text-sm text-center text-gray-900">
68+
<!-- Clickable user email address -->
6869
<a :href="'mailto:' + user.email">{{ user.email }}</a>
6970
</div>
7071
</td>
7172
<td class="px-6 py-4 whitespace-nowrap">
7273
<div class="text-sm text-center text-gray-900">
73-
{{ user.role.name }}
74+
<!-- Covering the case when there is no role -->
75+
{{ user.role ? user.role.name : 'Not available' }}
7476
</div>
7577
</td>
7678
<td class="px-6 py-4 text-center whitespace-nowrap">
7779
<span
7880
class="inline-flex px-2 text-xs font-semibold leading-5 text-green-800 bg-green-100 rounded-full">
79-
<!-- {{ user.formatted_created_at }} -->
81+
<!-- Formatted from user model appends propety -->
82+
{{ user.formatted_created_at }}
8083
</span>
8184
</td>
8285
<td class="px-6 py-4 text-sm font-medium text-right whitespace-nowrap">
@@ -118,6 +121,12 @@ export default {
118121
},
119122
props: {
120123
users: Object
124+
},
125+
methods: {
126+
deleteUser(user) {
127+
if (!confirm('Are you sure you want to delete user?')) return;
128+
this.$inertia.delete(route('users.destroy', user.id));
129+
}
121130
}
122131
}
123132
</script>

0 commit comments

Comments
 (0)