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>
48 lines
1.5 KiB
PHP
48 lines
1.5 KiB
PHP
<?php
|
|
|
|
use App\Http\Controllers\Api\ArticleController;
|
|
use App\Http\Controllers\Api\HomepageController;
|
|
use App\Http\Controllers\Api\PageController;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Support\Facades\Route;
|
|
|
|
/*
|
|
|--------------------------------------------------------------------------
|
|
| API Routes
|
|
|--------------------------------------------------------------------------
|
|
|
|
|
| Here is where you can register API routes for your application. These
|
|
| routes are loaded by the RouteServiceProvider and all of them will
|
|
| be assigned to the "api" middleware group. Make something great!
|
|
|
|
|
*/
|
|
|
|
Route::middleware('auth:sanctum')->get('/user', function (Request $request) {
|
|
return $request->user();
|
|
});
|
|
|
|
// Public API v1
|
|
Route::prefix('v1')->group(function () {
|
|
// Articles
|
|
Route::get('/articles', [ArticleController::class, 'index']);
|
|
Route::get('/articles/{slug}', [ArticleController::class, 'show']);
|
|
Route::get('/articles/{slug}/attachments/{id}/download', [ArticleController::class, 'downloadAttachment']);
|
|
|
|
// Categories
|
|
Route::get('/categories', function () {
|
|
$categories = \App\Models\ArticleCategory::withCount(['articles' => function ($q) {
|
|
$q->active()->forAccessLevel();
|
|
}])
|
|
->orderBy('sort_order')
|
|
->get();
|
|
|
|
return \App\Http\Resources\CategoryResource::collection($categories);
|
|
});
|
|
|
|
// Pages
|
|
Route::get('/pages/{slug}', [PageController::class, 'show']);
|
|
|
|
// Homepage
|
|
Route::get('/homepage', [HomepageController::class, 'index']);
|
|
});
|