axkuhta 1 gadu atpakaļ
vecāks
revīzija
362ddfccf9

+ 2 - 0
app/Console/Commands/LoadSampleData.php

@@ -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;

+ 17 - 0
app/Http/Controllers/ArticleController.php

@@ -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");
+	}
+}

+ 1 - 0
database/migrations/2023_12_02_171900_create_articles_table.php

@@ -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();

+ 18 - 0
resources/views/articles.blade.php

@@ -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

+ 1 - 0
resources/views/include/header.blade.php

@@ -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>

+ 3 - 0
routes/web.php

@@ -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']);