Compare commits
No commits in common. "146038cbba2a3c445f8b11f67ca9877995e54865" and "08ce25f11e668faee32ac5c1953294f44c8e2e30" have entirely different histories.
146038cbba
...
08ce25f11e
|
@ -2,73 +2,45 @@
|
||||||
|
|
||||||
namespace App\Http\Controllers;
|
namespace App\Http\Controllers;
|
||||||
|
|
||||||
use App\Http\Requests\UpdateUserRequest;
|
|
||||||
use App\Models\User;
|
use App\Models\User;
|
||||||
use Illuminate\Contracts\View\Factory;
|
use Illuminate\Http\Request;
|
||||||
use Illuminate\Contracts\View\View;
|
|
||||||
use Illuminate\Foundation\Application;
|
|
||||||
use Illuminate\Http\RedirectResponse;
|
|
||||||
use Illuminate\Support\Facades\Auth;
|
use Illuminate\Support\Facades\Auth;
|
||||||
|
|
||||||
class UserController extends Controller
|
class UserController extends Controller
|
||||||
{
|
{
|
||||||
public function index(): View|Application|Factory|\Illuminate\Contracts\Foundation\Application
|
public function index()
|
||||||
{
|
{
|
||||||
$users = User::all();
|
$users = User::all();
|
||||||
return view('users.index', compact('users'));
|
return view('users.index', compact('users'));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function store(UpdateUserRequest $request): RedirectResponse
|
public function store($request)
|
||||||
{
|
{
|
||||||
if (Auth::guest()) {
|
if (Auth::guest()) {
|
||||||
abort(403, 'Вы не авторизованы!');
|
abort(403, 'Вы не авторизованы!');
|
||||||
}
|
}
|
||||||
|
|
||||||
$validated = $request->validated();
|
$validated = $request->validated();
|
||||||
|
$createdById = Auth::id();
|
||||||
|
$data = [...$validated, 'created_by_id' => $createdById];
|
||||||
|
|
||||||
$user = new User();
|
$task = new User();
|
||||||
$user->name = $validated['name'];
|
$task->fill($data);
|
||||||
$user->password = $validated['password'];
|
$task->save();
|
||||||
$user->email = $validated['email'];
|
|
||||||
$user->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()) {
|
if (Auth::guest()) {
|
||||||
abort(403, 'Вы не авторизованы!');
|
abort(403, 'Вы не авторизованы!');
|
||||||
}
|
}
|
||||||
return view('users.create');
|
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');
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -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'
|
|
||||||
];
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -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'
|
|
||||||
];
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -4,9 +4,6 @@
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"packages": {
|
"packages": {
|
||||||
"": {
|
"": {
|
||||||
"dependencies": {
|
|
||||||
"@rails/ujs": "^7.1.2"
|
|
||||||
},
|
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@tailwindcss/forms": "^0.5.2",
|
"@tailwindcss/forms": "^0.5.2",
|
||||||
"alpinejs": "^3.4.2",
|
"alpinejs": "^3.4.2",
|
||||||
|
@ -508,11 +505,6 @@
|
||||||
"node": ">=14"
|
"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": {
|
"node_modules/@rollup/rollup-android-arm-eabi": {
|
||||||
"version": "4.9.4",
|
"version": "4.9.4",
|
||||||
"resolved": "https://registry.npmjs.org/@rollup/rollup-android-arm-eabi/-/rollup-android-arm-eabi-4.9.4.tgz",
|
"resolved": "https://registry.npmjs.org/@rollup/rollup-android-arm-eabi/-/rollup-android-arm-eabi-4.9.4.tgz",
|
||||||
|
|
|
@ -14,8 +14,5 @@
|
||||||
"postcss": "^8.4.31",
|
"postcss": "^8.4.31",
|
||||||
"tailwindcss": "^3.1.0",
|
"tailwindcss": "^3.1.0",
|
||||||
"vite": "^5.0.0"
|
"vite": "^5.0.0"
|
||||||
},
|
|
||||||
"dependencies": {
|
|
||||||
"@rails/ujs": "^7.1.2"
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,9 +1,7 @@
|
||||||
import './bootstrap';
|
import './bootstrap';
|
||||||
|
|
||||||
import Alpine from 'alpinejs';
|
import Alpine from 'alpinejs';
|
||||||
import ujs from '@rails/ujs';
|
|
||||||
|
|
||||||
window.Alpine = Alpine;
|
window.Alpine = Alpine;
|
||||||
|
|
||||||
Alpine.start();
|
Alpine.start();
|
||||||
ujs.start();
|
|
||||||
|
|
|
@ -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
|
|
|
@ -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>
|
<h2>список пользователей</h2>
|
||||||
|
|
||||||
<a href="{{ route('users.create') }}"> создать пользователя</a>
|
<a href="{{ route('users.create') }}"> создать пользователя</a>
|
||||||
|
@ -12,7 +9,6 @@
|
||||||
<th>id</th>
|
<th>id</th>
|
||||||
<td>name</td>
|
<td>name</td>
|
||||||
<td>email</td>
|
<td>email</td>
|
||||||
<td>действия</td>
|
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
|
@ -21,13 +17,59 @@
|
||||||
<td>{{ $user->id }}</td>
|
<td>{{ $user->id }}</td>
|
||||||
<td>{{ $user->name }}</td>
|
<td>{{ $user->name }}</td>
|
||||||
<td>{{ $user->email }}</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>
|
</tr>
|
||||||
@endforeach
|
@endforeach
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</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>--}}
|
||||||
|
|
Loading…
Reference in New Issue