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