1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950 |
- <?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(Author $author) {
- return view("author", ["author" => $author]);
- }
- function edit(Author $author) {
- return view("edit_author_form", ["author" => $author]);
- }
- function store(Request $request) {
- $request->validate([
- "id" => "nullable|exists:authors",
- "name" => "required",
- "description" => "nullable"
- ], [
- "name" => "Автор должен иметь имя."
- ]);
- $arr = $request;
- $author = Author::find($arr->id) ?? new Author;
- $author->name = $arr->name;
- $author->description = $arr->description;
- $author->save();
- return view("success");
- }
- function drop(Author $author) {
- $author->delete();
- return view("success");
- }
- }
|