Files
usher-manage-stack/database/migrations/2026_02_07_120002_create_articles_table.php
gbanyan a30af8eaf7 Add headless CMS for official site content management
Integrate article and page management into the Laravel admin dashboard
to serve as a headless CMS for the Next.js frontend (usher-site).

Backend:
- 7 migrations: article_categories, article_tags, articles, pivots, attachments, pages
- 5 models with relationships: Article, ArticleCategory, ArticleTag, ArticleAttachment, Page
- 4 admin controllers: articles (with publish/archive/pin), categories, tags, pages
- Admin views with EasyMDE markdown editor, multi-select categories/tags
- Navigation section "官網管理" in admin sidebar

API (v1):
- GET /api/v1/articles (filtered by type, category, tag, search; paginated)
- GET /api/v1/articles/{slug} (with related articles)
- GET /api/v1/categories
- GET /api/v1/pages/{slug} (with children)
- GET /api/v1/homepage (aggregated homepage data)
- Attachment download endpoint
- CORS configured for usher.org.tw, vercel.app, localhost:3000

Content migration:
- ImportHugoContent command: imports Hugo markdown files as articles/pages
- Successfully imported 27 articles, 17 categories, 11 tags, 9 pages

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-07 11:58:22 +08:00

47 lines
1.9 KiB
PHP

<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
public function up(): void
{
Schema::create('articles', function (Blueprint $table) {
$table->id();
$table->string('title');
$table->string('slug')->unique();
$table->text('summary')->nullable();
$table->longText('content');
$table->string('content_type'); // blog, notice, document, related_news
$table->string('status')->default('draft'); // draft, published, archived
$table->string('access_level')->default('public'); // public, members, board, admin
$table->string('featured_image_path')->nullable();
$table->string('featured_image_alt')->nullable();
$table->string('author_name')->nullable();
$table->foreignId('author_user_id')->nullable()->constrained('users')->nullOnDelete();
$table->text('meta_description')->nullable();
$table->json('meta_keywords')->nullable();
$table->boolean('is_pinned')->default(false);
$table->integer('display_order')->default(0);
$table->timestamp('published_at')->nullable();
$table->timestamp('expires_at')->nullable();
$table->timestamp('archived_at')->nullable();
$table->unsignedBigInteger('view_count')->default(0);
$table->foreignId('created_by_user_id')->constrained('users')->cascadeOnDelete();
$table->foreignId('last_updated_by_user_id')->nullable()->constrained('users')->nullOnDelete();
$table->softDeletes();
$table->timestamps();
$table->index(['status', 'content_type', 'published_at']);
$table->index('slug');
});
}
public function down(): void
{
Schema::dropIfExists('articles');
}
};