Compare commits

..

No commits in common. "146038cbba2a3c445f8b11f67ca9877995e54865" and "08ce25f11e668faee32ac5c1953294f44c8e2e30" have entirely different histories.

8 changed files with 80 additions and 193 deletions

View File

@ -2,73 +2,45 @@
namespace App\Http\Controllers;
use App\Http\Requests\UpdateUserRequest;
use App\Models\User;
use Illuminate\Contracts\View\Factory;
use Illuminate\Contracts\View\View;
use Illuminate\Foundation\Application;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
class UserController extends Controller
{
public function index(): View|Application|Factory|\Illuminate\Contracts\Foundation\Application
public function index()
{
$users = User::all();
return view('users.index', compact('users'));
}
public function store(UpdateUserRequest $request): RedirectResponse
public function store($request)
{
if (Auth::guest()) {
abort(403, 'Вы не авторизованы!');
}
$validated = $request->validated();
$createdById = Auth::id();
$data = [...$validated, 'created_by_id' => $createdById];
$user = new User();
$user->name = $validated['name'];
$user->password = $validated['password'];
$user->email = $validated['email'];
$user->save();
$task = new User();
$task->fill($data);
$task->save();
return redirect()->route('users.index');
if (array_key_exists('labels', $validated)) {
$task->labels()->attach($validated['labels']);
}
public function create(): View|Application|Factory|\Illuminate\Contracts\Foundation\Application
$message = __('controllers.tasks_create');
return redirect()->route('tasks.index');
}
public function create()
{
if (Auth::guest()) {
abort(403, 'Вы не авторизованы!');
}
return view('users.create');
}
public function edit(User $user): View|Application|Factory|\Illuminate\Contracts\Foundation\Application
{
if (Auth::guest()) {
abort(403, 'Вы не авторизованы!');
}
return view('users.edit', compact('user'));
}
public function update(UpdateUserRequest $request, User $user): RedirectResponse
{
if (Auth::guest()) {
abort(403, 'Вы не авторизованы!');
}
$validated = $request->validated();
$user->fill($validated);
$user->save();
return redirect()->route('users.index');
}
public function destroy(User $user): RedirectResponse
{
$user->delete();
return redirect()->route('users.index');
}
}

View File

@ -1,32 +0,0 @@
<?php
namespace App\Http\Requests;
use Illuminate\Foundation\Http\FormRequest;
class StoreUserRequest extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize()
{
return true;
}
/**
* Get the validation rules that apply to the request.
*
* @return array<string, mixed>
*/
public function rules()
{
return [
'name' => 'required|unique:users,name|max:255',
'email' => 'email:rfc,dns',
'password' => 'required'
];
}
}

View File

@ -1,32 +0,0 @@
<?php
namespace App\Http\Requests;
use Illuminate\Foundation\Http\FormRequest;
class UpdateUserRequest extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize()
{
return true;
}
/**
* Get the validation rules that apply to the request.
*
* @return array<string, mixed>
*/
public function rules()
{
return [
'name' => 'required|unique:users,name|max:255',
'email' => 'email:rfc,dns',
'password' => 'required'
];
}
}

8
package-lock.json generated
View File

@ -4,9 +4,6 @@
"requires": true,
"packages": {
"": {
"dependencies": {
"@rails/ujs": "^7.1.2"
},
"devDependencies": {
"@tailwindcss/forms": "^0.5.2",
"alpinejs": "^3.4.2",
@ -508,11 +505,6 @@
"node": ">=14"
}
},
"node_modules/@rails/ujs": {
"version": "7.1.2",
"resolved": "https://registry.npmjs.org/@rails/ujs/-/ujs-7.1.2.tgz",
"integrity": "sha512-c5x02djEKEVVE4qfN4XgElJS4biM0xxtIVpcJ0ZHLK116U19rowTtmD0AJ/RCb3Xaewa4GPIWLlwgeC0dCQqzw=="
},
"node_modules/@rollup/rollup-android-arm-eabi": {
"version": "4.9.4",
"resolved": "https://registry.npmjs.org/@rollup/rollup-android-arm-eabi/-/rollup-android-arm-eabi-4.9.4.tgz",

View File

@ -14,8 +14,5 @@
"postcss": "^8.4.31",
"tailwindcss": "^3.1.0",
"vite": "^5.0.0"
},
"dependencies": {
"@rails/ujs": "^7.1.2"
}
}

View File

@ -1,9 +1,7 @@
import './bootstrap';
import Alpine from 'alpinejs';
import ujs from '@rails/ujs';
window.Alpine = Alpine;
Alpine.start();
ujs.start();

View File

@ -1,50 +0,0 @@
@auth()
<div class="grid col-span-full">
<h1 class="max-w-2xl mb-4 text-4xl leading-none tracking-tight md:text-5xl xl:text-6xl dark:text-white"> Изменить
пользователя</h1>
{{ Form::open(['url' => route('users.update', $user), 'method' => 'PATCH', 'class' => 'w-50']) }}
<div class="flex flex-col">
<div>
{{ Form::label('name', 'Логин') }}
</div>
<div class="mt-2">
{{ Form::text('name', $user->name, ['class' => 'form-control rounded border-gray-300 w-1/3']) }}
</div>
<div>
@if ($errors->any())
{{ $errors->first('name') }}
@endif
</div>
<div>
{{ Form::label('email', 'электронная почта') }}
</div>
<div class="mt-2">
{{ Form::text('email', $user->email, ['class' => 'form-control rounded border-gray-300 w-1/3']) }}
</div>
<div>
@if ($errors->any())
{{ $errors->first('email') }}
@endif
</div>
<div>
{{ Form::label('password', 'Пароль') }}
</div>
<div class="mt-2">
{{ Form::text('password', '', ['class' => 'form-control rounded border-gray-300 w-1/3']) }}
</div>
<div>
@if ($errors->any())
{{ $errors->first('password') }}
@endif
</div>
<div class="mt-4">
{{ Form::submit('изменить', ['class' => 'bg-blue-500 hover:bg-blue-700 text-white font-bold py-2 px-4 rounded']) }}
</div>
</div>
{{ Form::close() }}
</div>
@endauth

View File

@ -1,6 +1,3 @@
<meta name="csrf-token" content="{{ csrf_token() }}">
<meta name="csrf-param" content="_token" />
@vite(['resources/css/app.css', 'resources/js/app.js'])
<h2>список пользователей</h2>
<a href="{{ route('users.create') }}"> создать пользователя</a>
@ -12,7 +9,6 @@
<th>id</th>
<td>name</td>
<td>email</td>
<td>действия</td>
</tr>
</thead>
<tbody>
@ -21,13 +17,59 @@
<td>{{ $user->id }}</td>
<td>{{ $user->name }}</td>
<td>{{ $user->email }}</td>
<td><a href="{{ route("users.edit", $user) }}">редактировать</a></td>
<td><a rel="nofollow" data-method="delete" data-confirm="Вы действительно хотите удалить?"
href="{{ route('users.destroy', $user) }}">
удалить
</a>
</td>
</tr>
@endforeach
</tbody>
</table>
{{--<table class="mt-4">--}}
{{-- <thead class="border-b-2 border-solid border-black text-left" style="text-align: left">--}}
{{-- <tr>--}}
{{-- <th>{{ __('layout.table_id') }}</th>--}}
{{-- <th>{{ __('layout.table_task_status') }}</th>--}}
{{-- <th>{{ __('layout.table_name') }}</th>--}}
{{-- <th>{{ __('layout.table_creater') }}</th>--}}
{{-- <th>{{ __('layout.table_assigned') }}</th>--}}
{{-- <th>{{ __('layout.table_date_of_creation') }}</th>--}}
{{-- @auth()--}}
{{-- <th>{{ __('layout.table_actions') }}</th>--}}
{{-- @endauth--}}
{{-- </tr>--}}
{{-- </thead>--}}
{{-- <tbody>--}}
{{-- @foreach($tasks as $task)--}}
{{-- <tr class="border-b border-dashed text-left">--}}
{{-- <td>{{ $task->id }}</td>--}}
{{-- <td>{{ $taskStatuses[$task->status_id] }}</td>--}}
{{-- <td><a href="{{ route('tasks.show', $task) }}">{{ $task->name }}</a></td>--}}
{{-- <td>{{ $users[$task->created_by_id] }}</td>--}}
{{-- <td>{{ $users[$task->assigned_to_id] }}</td>--}}
{{-- <td>{{ date_format($task->created_at, 'd.m.Y') }}</td>--}}
{{-- @auth()--}}
{{-- <td>--}}
{{-- @can('delete', $task)--}}
{{-- <a--}}
{{-- class="text-red-600 hover:text-red-900"--}}
{{-- rel="nofollow"--}}
{{-- data-method="delete"--}}
{{-- data-confirm="{{ __('layout.table_delete_question') }}"--}}
{{-- href="{{ route('tasks.destroy', $task) }}"--}}
{{-- >--}}
{{-- {{ __('layout.table_delete') }}--}}
{{-- </a>--}}
{{-- @endcan--}}
{{-- @can('update', $task)--}}
{{-- <a class="text-blue-600 hover:text-blue-900"--}}
{{-- href="{{ route("tasks.edit", $task) }}"--}}
{{-- >--}}
{{-- {{ __('layout.table_edit') }}--}}
{{-- </a>--}}
{{-- @endcan--}}
{{-- </td>--}}
{{-- @endauth--}}
{{-- </tr>--}}
{{-- @endforeach--}}
{{-- </tbody>--}}
{{--</table>--}}