LaravelTest
76 строк · 1.6 Кб
1<?php
2
3namespace App\Http\Controllers;
4
5use App\Models\User;
6use Illuminate\Http\Request;
7use App\Http\Requests\UsersRequest;
8use App\Http\Requests\UsersUpdateRequest;
9
10class UsersController extends Controller
11{
12/**
13* Display a listing of the resource.
14*/
15public function index()
16{
17$users = User::all();
18return view('users.index', compact('users'));
19
20}
21
22/**
23* Show the form for creating a new resource.
24*/
25public function create()
26{
27return view('users.create');
28}
29
30/**
31* Store a newly created resource in storage.
32*/
33public function store(UsersRequest $request)
34{
35$date = $request->validated();
36User::firstOrCreate([
37'email' => $date['email']
38], $date);
39return redirect()->route('users.index');
40}
41
42/**
43* Display the specified resource.
44*/
45public function show(User $user)
46{
47return view('users.show', compact('user'));
48}
49
50/**
51* Show the form for editing the specified resource.
52*/
53public function edit(User $user)
54{
55return view('users.edite', compact('user'));
56}
57
58/**
59* Update the specified resource in storage.
60*/
61public function update(UsersUpdateRequest $request, User $user)
62{
63$date = $request->validated();
64$user->update($date);
65return redirect()->route('users.show', compact('user'));
66}
67
68/**
69* Remove the specified resource from storage.
70*/
71public function destroy(User $user)
72{
73$user->delete();
74return redirect()->route('users.index', compact('user'));
75}
76}