AuthorController.php 735 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. <?php
  2. namespace App\Http\Controllers;
  3. use Illuminate\Http\Request;
  4. use App\Models\Author;
  5. class AuthorController extends Controller {
  6. function index() {
  7. $authors = Author::all();
  8. return view("authors", ["rows" => $authors]);
  9. }
  10. function add() {
  11. return view("add_author_form");
  12. }
  13. function view(Author $author) {
  14. return view("author", ["author" => $author]);
  15. }
  16. function store(Request $request) {
  17. $request->validate([
  18. "name" => "required",
  19. "description" => "nullable"
  20. ], [
  21. "name" => "Автор должен иметь имя."
  22. ]);
  23. $arr = $request;
  24. $author = new Author;
  25. $author->name = $arr->name;
  26. $author->description = $arr->description;
  27. $author->save();
  28. return view("success");
  29. }
  30. }