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>
This commit is contained in:
@@ -0,0 +1,25 @@
|
||||
<?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('article_categories', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->string('name');
|
||||
$table->string('slug')->unique();
|
||||
$table->text('description')->nullable();
|
||||
$table->integer('sort_order')->default(0);
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('article_categories');
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,23 @@
|
||||
<?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('article_tags', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->string('name');
|
||||
$table->string('slug')->unique();
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('article_tags');
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,46 @@
|
||||
<?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');
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,22 @@
|
||||
<?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('article_category', function (Blueprint $table) {
|
||||
$table->foreignId('article_id')->constrained()->cascadeOnDelete();
|
||||
$table->foreignId('category_id')->constrained('article_categories')->cascadeOnDelete();
|
||||
$table->primary(['article_id', 'category_id']);
|
||||
});
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('article_category');
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,22 @@
|
||||
<?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('article_tag', function (Blueprint $table) {
|
||||
$table->foreignId('article_id')->constrained()->cascadeOnDelete();
|
||||
$table->foreignId('tag_id')->constrained('article_tags')->cascadeOnDelete();
|
||||
$table->primary(['article_id', 'tag_id']);
|
||||
});
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('article_tag');
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,28 @@
|
||||
<?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('article_attachments', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->foreignId('article_id')->constrained()->cascadeOnDelete();
|
||||
$table->string('file_path');
|
||||
$table->string('original_filename');
|
||||
$table->string('mime_type');
|
||||
$table->unsignedBigInteger('file_size');
|
||||
$table->string('description')->nullable();
|
||||
$table->unsignedBigInteger('download_count')->default(0);
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('article_attachments');
|
||||
}
|
||||
};
|
||||
35
database/migrations/2026_02_07_120006_create_pages_table.php
Normal file
35
database/migrations/2026_02_07_120006_create_pages_table.php
Normal file
@@ -0,0 +1,35 @@
|
||||
<?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('pages', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->string('title');
|
||||
$table->string('slug')->unique();
|
||||
$table->longText('content');
|
||||
$table->string('template')->nullable();
|
||||
$table->json('custom_fields')->nullable();
|
||||
$table->string('status')->default('draft'); // draft, published
|
||||
$table->text('meta_description')->nullable();
|
||||
$table->json('meta_keywords')->nullable();
|
||||
$table->foreignId('parent_id')->nullable()->constrained('pages')->nullOnDelete();
|
||||
$table->integer('sort_order')->default(0);
|
||||
$table->timestamp('published_at')->nullable();
|
||||
$table->foreignId('created_by_user_id')->constrained('users')->cascadeOnDelete();
|
||||
$table->foreignId('last_updated_by_user_id')->nullable()->constrained('users')->nullOnDelete();
|
||||
$table->softDeletes();
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('pages');
|
||||
}
|
||||
};
|
||||
@@ -90,6 +90,21 @@ class FinancialWorkflowPermissionsSeeder extends Seeder
|
||||
'delete_announcements' => '刪除公告',
|
||||
'publish_announcements' => '發布公告',
|
||||
'manage_all_announcements' => '管理所有公告',
|
||||
|
||||
// ===== 官網文章管理權限 =====
|
||||
'view_articles' => '查看官網文章',
|
||||
'create_articles' => '建立官網文章',
|
||||
'edit_articles' => '編輯官網文章',
|
||||
'delete_articles' => '刪除官網文章',
|
||||
'publish_articles' => '發布官網文章',
|
||||
'manage_all_articles' => '管理所有官網文章',
|
||||
|
||||
// ===== 官網頁面管理權限 =====
|
||||
'view_pages' => '查看官網頁面',
|
||||
'create_pages' => '建立官網頁面',
|
||||
'edit_pages' => '編輯官網頁面',
|
||||
'delete_pages' => '刪除官網頁面',
|
||||
'publish_pages' => '發布官網頁面',
|
||||
];
|
||||
|
||||
foreach ($permissions as $name => $description) {
|
||||
@@ -131,6 +146,19 @@ class FinancialWorkflowPermissionsSeeder extends Seeder
|
||||
'delete_announcements',
|
||||
'publish_announcements',
|
||||
'manage_all_announcements',
|
||||
// 官網文章管理
|
||||
'view_articles',
|
||||
'create_articles',
|
||||
'edit_articles',
|
||||
'delete_articles',
|
||||
'publish_articles',
|
||||
'manage_all_articles',
|
||||
// 官網頁面管理
|
||||
'view_pages',
|
||||
'create_pages',
|
||||
'edit_pages',
|
||||
'delete_pages',
|
||||
'publish_pages',
|
||||
],
|
||||
'description' => '秘書長 - 協會行政負責人,負責初審所有財務申請',
|
||||
],
|
||||
@@ -227,6 +255,19 @@ class FinancialWorkflowPermissionsSeeder extends Seeder
|
||||
'delete_announcements',
|
||||
'publish_announcements',
|
||||
'manage_all_announcements',
|
||||
// 官網文章管理
|
||||
'view_articles',
|
||||
'create_articles',
|
||||
'edit_articles',
|
||||
'delete_articles',
|
||||
'publish_articles',
|
||||
'manage_all_articles',
|
||||
// 官網頁面管理
|
||||
'view_pages',
|
||||
'create_pages',
|
||||
'edit_pages',
|
||||
'delete_pages',
|
||||
'publish_pages',
|
||||
],
|
||||
'description' => '理事長 - 協會負責人,負責核決重大財務支出與會員繳費最終審核',
|
||||
],
|
||||
@@ -244,6 +285,11 @@ class FinancialWorkflowPermissionsSeeder extends Seeder
|
||||
'edit_announcements',
|
||||
'delete_announcements',
|
||||
'publish_announcements',
|
||||
// 官網文章管理
|
||||
'view_articles',
|
||||
'create_articles',
|
||||
'edit_articles',
|
||||
'publish_articles',
|
||||
],
|
||||
'description' => '理事 - 理事會成員,協助監督協會運作與審核特定議案',
|
||||
],
|
||||
@@ -267,6 +313,11 @@ class FinancialWorkflowPermissionsSeeder extends Seeder
|
||||
'edit_announcements',
|
||||
'delete_announcements',
|
||||
'publish_announcements',
|
||||
// 官網文章管理
|
||||
'view_articles',
|
||||
'create_articles',
|
||||
'edit_articles',
|
||||
'publish_articles',
|
||||
],
|
||||
'description' => '會員管理員 - 專責處理會員入會審核、資料維護與會籍管理',
|
||||
],
|
||||
|
||||
Reference in New Issue
Block a user