Roman_applicant-site/app/Http/Controllers/UserController.php

47 lines
1.1 KiB
PHP
Raw Permalink Normal View History

2024-01-11 15:10:01 +03:00
<?php
namespace App\Http\Controllers;
use App\Models\User;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
class UserController extends Controller
{
public function index()
{
$users = User::all();
return view('users.index', compact('users'));
}
public function store($request)
{
if (Auth::guest()) {
2024-01-12 09:56:06 +03:00
abort(403, 'Вы не авторизованы!');
2024-01-11 15:10:01 +03:00
}
$validated = $request->validated();
$createdById = Auth::id();
$data = [...$validated, 'created_by_id' => $createdById];
$task = new User();
$task->fill($data);
$task->save();
if (array_key_exists('labels', $validated)) {
$task->labels()->attach($validated['labels']);
}
$message = __('controllers.tasks_create');
return redirect()->route('tasks.index');
}
2024-01-12 09:56:06 +03:00
public function create()
{
if (Auth::guest()) {
abort(403, 'Вы не авторизованы!');
}
return view('users.create');
}
2024-01-11 15:10:01 +03:00
}