forked from aslan/applicant-site
39 lines
888 B
PHP
39 lines
888 B
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()) {
|
||
|
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');
|
||
|
}
|
||
|
}
|