95 lines
1.9 KiB
PHP
95 lines
1.9 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
use App\Models\User;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Support\Facades\Hash;
|
|
use Illuminate\View\View;
|
|
|
|
class UserController extends Controller
|
|
{
|
|
/**
|
|
* Display a listing of the resource.
|
|
*/
|
|
public function index(): View
|
|
{
|
|
return view("users.index", [
|
|
"users" => User::all()
|
|
]);
|
|
}
|
|
|
|
/**
|
|
* Show the form for creating a new resource.
|
|
*/
|
|
public function create()
|
|
{
|
|
//
|
|
}
|
|
|
|
/**
|
|
* Store a newly created resource in storage.
|
|
*/
|
|
public function store(Request $request)
|
|
{
|
|
$validated = $request->validate([
|
|
"name" => "required|string",
|
|
"email" => "required|email",
|
|
"password" => "required|confirmed",
|
|
]);
|
|
|
|
$user = User::create([
|
|
'name' => $request->name,
|
|
'email' => $request->email,
|
|
'password' => Hash::make($request->password),
|
|
'role' => $request->role
|
|
]);
|
|
|
|
return redirect(route("users.index"));
|
|
}
|
|
|
|
/**
|
|
* Display the specified resource.
|
|
*/
|
|
public function show(User $user)
|
|
{
|
|
//
|
|
}
|
|
|
|
/**
|
|
* Show the form for editing the specified resource.
|
|
*/
|
|
public function edit(User $user)
|
|
{
|
|
return view("users.edit", [
|
|
"user" => $user
|
|
]);
|
|
}
|
|
|
|
/**
|
|
* Update the specified resource in storage.
|
|
*/
|
|
public function update(Request $request, User $user)
|
|
{
|
|
$validated = $request->validate([
|
|
"name" => "required|string",
|
|
"email" => "required|email",
|
|
"password" => "confirmed",
|
|
]);
|
|
|
|
$user->update(array_filter($validated));
|
|
|
|
return redirect(route("users.index"));
|
|
}
|
|
|
|
/**
|
|
* Remove the specified resource from storage.
|
|
*/
|
|
public function destroy(User $user)
|
|
{
|
|
$user->delete();
|
|
|
|
return redirect(route("users.index"));
|
|
}
|
|
}
|