Update users

This commit is contained in:
Александр Бабкин
2022-06-24 16:51:08 +03:00
parent 7a46864d33
commit 310613e9a8
4 changed files with 117 additions and 32 deletions

View File

@@ -79,7 +79,8 @@ class UserController extends Controller
*/ */
public function edit($id) public function edit($id)
{ {
// $user = User::find($id);
return view('admin.users.edit',['user'=>$user]);
} }
/** /**
@@ -91,7 +92,20 @@ class UserController extends Controller
*/ */
public function update(Request $request, $id) public function update(Request $request, $id)
{ {
// $request->validate([
'username' => 'required|string|max:255|unique:users,username,'.$id,
'name' => 'required|string|max:255',
'email' => 'required|email|unique:users,email,'.$id,
]);
$user = User::find($id);
$user->username = $request->username;
$user->name = $request->name;
$user->email = $request->email;
$user->save();
return redirect(route('users.index'));
} }
/** /**

View File

@@ -710,6 +710,15 @@ select {
.-ml-px { .-ml-px {
margin-left: -1px; margin-left: -1px;
} }
.mt-1 {
margin-top: 0.25rem;
}
.mt-4 {
margin-top: 1rem;
}
.ml-4 {
margin-left: 1rem;
}
.ml-1 { .ml-1 {
margin-left: 0.25rem; margin-left: 0.25rem;
} }
@@ -722,12 +731,6 @@ select {
.ml-2 { .ml-2 {
margin-left: 0.5rem; margin-left: 0.5rem;
} }
.mt-4 {
margin-top: 1rem;
}
.ml-4 {
margin-left: 1rem;
}
.mt-8 { .mt-8 {
margin-top: 2rem; margin-top: 2rem;
} }
@@ -746,9 +749,6 @@ select {
.mb-4 { .mb-4 {
margin-bottom: 1rem; margin-bottom: 1rem;
} }
.mt-1 {
margin-top: 0.25rem;
}
.mt-6 { .mt-6 {
margin-top: 1.5rem; margin-top: 1.5rem;
} }
@@ -797,6 +797,9 @@ select {
.w-5 { .w-5 {
width: 1.25rem; width: 1.25rem;
} }
.w-full {
width: 100%;
}
.w-8 { .w-8 {
width: 2rem; width: 2rem;
} }
@@ -815,15 +818,15 @@ select {
.w-20 { .w-20 {
width: 5rem; width: 5rem;
} }
.w-full {
width: 100%;
}
.max-w-7xl { .max-w-7xl {
max-width: 80rem; max-width: 80rem;
} }
.max-w-6xl { .max-w-6xl {
max-width: 72rem; max-width: 72rem;
} }
.max-w-xl {
max-width: 36rem;
}
.flex-1 { .flex-1 {
flex: 1 1 0%; flex: 1 1 0%;
} }
@@ -912,18 +915,21 @@ select {
.border { .border {
border-width: 1px; border-width: 1px;
} }
.border-t {
border-top-width: 1px;
}
.border-b { .border-b {
border-bottom-width: 1px; border-bottom-width: 1px;
} }
.border-t {
border-top-width: 1px;
}
.border-b-2 { .border-b-2 {
border-bottom-width: 2px; border-bottom-width: 2px;
} }
.border-l-4 { .border-l-4 {
border-left-width: 4px; border-left-width: 4px;
} }
.border-r {
border-right-width: 1px;
}
.border-gray-300 { .border-gray-300 {
--tw-border-opacity: 1; --tw-border-opacity: 1;
border-color: rgb(209 213 219 / var(--tw-border-opacity)); border-color: rgb(209 213 219 / var(--tw-border-opacity));
@@ -943,6 +949,10 @@ select {
--tw-border-opacity: 1; --tw-border-opacity: 1;
border-color: rgb(129 140 248 / var(--tw-border-opacity)); border-color: rgb(129 140 248 / var(--tw-border-opacity));
} }
.border-gray-400 {
--tw-border-opacity: 1;
border-color: rgb(156 163 175 / var(--tw-border-opacity));
}
.bg-white { .bg-white {
--tw-bg-opacity: 1; --tw-bg-opacity: 1;
background-color: rgb(255 255 255 / var(--tw-bg-opacity)); background-color: rgb(255 255 255 / var(--tw-bg-opacity));
@@ -984,6 +994,10 @@ select {
padding-top: 1.5rem; padding-top: 1.5rem;
padding-bottom: 1.5rem; padding-bottom: 1.5rem;
} }
.py-12 {
padding-top: 3rem;
padding-bottom: 3rem;
}
.py-4 { .py-4 {
padding-top: 1rem; padding-top: 1rem;
padding-bottom: 1rem; padding-bottom: 1rem;
@@ -996,10 +1010,6 @@ select {
padding-top: 0.25rem; padding-top: 0.25rem;
padding-bottom: 0.25rem; padding-bottom: 0.25rem;
} }
.py-12 {
padding-top: 3rem;
padding-bottom: 3rem;
}
.px-1 { .px-1 {
padding-left: 0.25rem; padding-left: 0.25rem;
padding-right: 0.25rem; padding-right: 0.25rem;
@@ -1041,6 +1051,10 @@ select {
font-size: 0.875rem; font-size: 0.875rem;
line-height: 1.25rem; line-height: 1.25rem;
} }
.text-xl {
font-size: 1.25rem;
line-height: 1.75rem;
}
.text-lg { .text-lg {
font-size: 1.125rem; font-size: 1.125rem;
line-height: 1.75rem; line-height: 1.75rem;
@@ -1049,10 +1063,6 @@ select {
font-size: 1rem; font-size: 1rem;
line-height: 1.5rem; line-height: 1.5rem;
} }
.text-xl {
font-size: 1.25rem;
line-height: 1.75rem;
}
.text-xs { .text-xs {
font-size: 0.75rem; font-size: 0.75rem;
line-height: 1rem; line-height: 1rem;
@@ -1069,15 +1079,18 @@ select {
.leading-5 { .leading-5 {
line-height: 1.25rem; line-height: 1.25rem;
} }
.leading-7 {
line-height: 1.75rem;
}
.leading-tight { .leading-tight {
line-height: 1.25; line-height: 1.25;
} }
.leading-7 {
line-height: 1.75rem;
}
.tracking-widest { .tracking-widest {
letter-spacing: 0.1em; letter-spacing: 0.1em;
} }
.tracking-wider {
letter-spacing: 0.05em;
}
.text-gray-500 { .text-gray-500 {
--tw-text-opacity: 1; --tw-text-opacity: 1;
color: rgb(107 114 128 / var(--tw-text-opacity)); color: rgb(107 114 128 / var(--tw-text-opacity));
@@ -1086,6 +1099,10 @@ select {
--tw-text-opacity: 1; --tw-text-opacity: 1;
color: rgb(55 65 81 / var(--tw-text-opacity)); color: rgb(55 65 81 / var(--tw-text-opacity));
} }
.text-gray-800 {
--tw-text-opacity: 1;
color: rgb(31 41 55 / var(--tw-text-opacity));
}
.text-gray-200 { .text-gray-200 {
--tw-text-opacity: 1; --tw-text-opacity: 1;
color: rgb(229 231 235 / var(--tw-text-opacity)); color: rgb(229 231 235 / var(--tw-text-opacity));
@@ -1106,10 +1123,6 @@ select {
--tw-text-opacity: 1; --tw-text-opacity: 1;
color: rgb(17 24 39 / var(--tw-text-opacity)); color: rgb(17 24 39 / var(--tw-text-opacity));
} }
.text-gray-800 {
--tw-text-opacity: 1;
color: rgb(31 41 55 / var(--tw-text-opacity));
}
.text-green-600 { .text-green-600 {
--tw-text-opacity: 1; --tw-text-opacity: 1;
color: rgb(22 163 74 / var(--tw-text-opacity)); color: rgb(22 163 74 / var(--tw-text-opacity));

View File

@@ -0,0 +1,54 @@
<x-app-layout>
<x-slot name="header">
<h2 class="font-semibold text-xl text-gray-800 leading-tight">
{{ __('Edit user') }}
</h2>
</x-slot>
<div class="py-12">
<div class="max-w-7xl mx-auto sm:px-6 lg:px-8">
<div class="bg-white overflow-hidden shadow-sm sm:rounded-lg">
<div class="p-6 bg-white border-b border-gray-200">
<x-auth-validation-errors class="mb-4" :errors="$errors" />
<form method="POST" action="{{ route('users.update', $user->id) }}">
@csrf
@method('PUT')
<!-- User name -->
<!-- <input type="hidden" name="id" id="id" value="{{ $user->id}}"> -->
<div>
<x-label for="username" :value="__('User name')" />
<x-input id="username" class="block mt-1 w-full" type="text" name="username" value="{{ $user->username }}" required autofocus />
</div>
<!-- Name -->
<div>
<x-label for="name" :value="__('Name')" />
<x-input id="name" class="block mt-1 w-full" type="text" name="name" value="{{ $user->name }}" required />
</div>
<!-- Email Address -->
<div class="mt-4">
<x-label for="email" :value="__('Email')" />
<x-input id="email" class="block mt-1 w-full" type="email" name="email" value="{{ $user->email }}" required />
</div>
<div class="flex items-center justify-end mt-4">
<!-- <button type="submit" class="btn">{{ __('Save') }}</button> -->
<x-button class="ml-4">
{{ __('Save') }}
</x-button>
<!-- <a href="{{ route('users.index') }}">
<x-button class="ml-4">
{{ __('Cancel') }}
</x-button>
</a> -->
</div>
</form>
</div>
</div>
</div>
</div>
</x-app-layout>

View File

@@ -20,6 +20,9 @@
<th class="p-2 border border-gray-200"> <th class="p-2 border border-gray-200">
{{ __('User name')}} {{ __('User name')}}
</th> </th>
<th class="p-2 border border-gray-200">
{{ __('Name')}}
</th>
<th class="p-2 border border-gray-200"> <th class="p-2 border border-gray-200">
{{ __('Email')}} {{ __('Email')}}
</th> </th>
@@ -30,6 +33,7 @@
@foreach ( $users as $user) @foreach ( $users as $user)
<tr class="border border-gray-200"> <tr class="border border-gray-200">
<td class="p-2 border border-gray-200"><a href="{{ route('users.show',$user->id)}}" class="underline">{{ $user->username }}</a></td> <td class="p-2 border border-gray-200"><a href="{{ route('users.show',$user->id)}}" class="underline">{{ $user->username }}</a></td>
<td class="p-2 border border-gray-200">{{ $user->name }}</td>
<td class="p-2 border border-gray-200">{{ $user->email }}</td> <td class="p-2 border border-gray-200">{{ $user->email }}</td>
<td class="p-2 border border-gray-200">&nbsp;</td> <td class="p-2 border border-gray-200">&nbsp;</td>
</tr> </tr>