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

39 lines
888 B
PHP
Raw 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()) {
return redirect()->route('tasks.index');
}
$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');
}
}