12345678910111213141516171819202122232425262728293031323334353637383940 |
- <?php
- namespace App\Http\Controllers;
- use Illuminate\Http\Request;
- use App\Models\Author;
- class AuthorController extends Controller {
- function index() {
- $authors = Author::all();
- return view("authors", ["rows" => $authors]);
- }
- function add() {
- return view("add_author_form");
- }
- function view($id) {
- return ["id" => $id];
- }
- function store(Request $request) {
- $request->validate([
- "name" => "required",
- "description" => "nullable"
- ], [
- "name" => "Автор должен иметь имя."
- ]);
- $arr = $request;
- $author = new Author;
- $author->name = $arr->name;
- $author->description = $arr->description;
- $author->save();
- return view("success");
- }
- }
|