@@ -30,7 +30,9 @@ class LoadSampleData extends Command
{
$article = new Article;
$article->title = "Test article";
+ $article->description = "Short description";
$article->content = "Test article contents";
+ $article->publish_at = now();
$article->save();
$author = new Author;
@@ -0,0 +1,17 @@
+<?php
+
+namespace App\Http\Controllers;
+use Illuminate\Http\Request;
+use App\Models\Article;
+class ArticleController extends Controller
+{
+ function index() {
+ return view("articles", ["rows" => Article::all()]);
+ }
+ function add() {
+ return view("add_article_form");
+}
@@ -16,6 +16,7 @@ return new class extends Migration
$table->timestamps();
$table->softDeletes();
$table->string("title");
+ $table->string("description");
$table->text("content");
$table->timestamp("publish_at")->nullable();
$table->timestamp("unpublish_at")->nullable();
@@ -0,0 +1,18 @@
+@extends("layouts.app")
+@section("content")
+<h1>Все публикации</h1>
+<div class="article-list">
+@foreach ($rows as $row)
+ <div>
+ <h2>{{$row->title}}</h2>
+ <p>{{$row->description}}</p>
+ <a href="/article/{{$row->id}}">ОТКРЫТЬ</a> | Опубликовано: {{$row->publish_at}}
+ </div>
+@endforeach
+</div>
+<p><a href="/author/add">Добавить публикацию</a></p>
+@endsection
@@ -2,6 +2,7 @@
<a href="/" class="logo">LaravelDemo</a>
<div class="container">
<a href="/">Главная</a>
+<a href="/articles">Публикации</a>
<a href="/authors">Авторы</a>
<a href="/books">Книги</a>
</div>
@@ -43,3 +43,6 @@ Route::post('/author/add', [Controllers\AuthorController::class, 'store']);
// API
Route::get('/api/authors', function() { return Resources\AuthorResource::collection(Models\Author::all()); });
Route::get('/api/books', function() { return Resources\BookResource::collection(Models\Book::all()->load("author")); });
+// Публикации
+Route::get('/articles', [Controllers\ArticleController::class, 'index']);