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

47 lines
1.1 KiB
PHP

<?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()) {
abort(403, 'Вы не авторизованы!');
}
$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');
}
public function create()
{
if (Auth::guest()) {
abort(403, 'Вы не авторизованы!');
}
return view('users.create');
}
}