feat: 前台 .shtml 后缀 canonical + strict_types 全量启用 + 对外 API(Sanctum+Scramble 文档)+ pm2 ecosystem + GitHub Actions CI + 插件/主题/架构/API 文档 + REDIS_PREFIX 说明

This commit is contained in:
ak
2026-08-11 19:37:33 +08:00
parent 1c8a801238
commit fc6624cf84
244 changed files with 1902 additions and 97 deletions
+2
View File
@@ -45,6 +45,8 @@ MEMCACHED_HOST=127.0.0.1
REDIS_CLIENT=phpredis REDIS_CLIENT=phpredis
REDIS_HOST=127.0.0.1 REDIS_HOST=127.0.0.1
REDIS_PASSWORD=null REDIS_PASSWORD=null
# redis key 前缀(默认由 APP_NAME 生成,如 laralog-database-);多应用共用 redis 时务必区分
REDIS_PREFIX=
REDIS_PORT=6379 REDIS_PORT=6379
MAIL_MAILER=log MAIL_MAILER=log
+94
View File
@@ -0,0 +1,94 @@
name: CI
on:
push:
branches: [main, master, develop]
pull_request:
jobs:
test:
runs-on: ubuntu-latest
services:
mysql:
image: mysql:8.0
env:
MYSQL_ROOT_PASSWORD: root
MYSQL_DATABASE: laralog_test
ports:
- 3306:3306
options: >-
--health-cmd="mysqladmin ping -proot"
--health-interval=10s
--health-timeout=5s
--health-retries=5
steps:
- uses: actions/checkout@v4
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.2'
extensions: mbstring, dom, pdo_mysql, sqlite3, gd, redis
coverage: none
- name: Cache Composer
uses: actions/cache@v4
with:
path: vendor
key: composer-${{ hashFiles('composer.lock') }}
- name: Install dependencies
run: composer install --no-interaction --prefer-dist --no-progress
- name: Env
run: |
cp .env.example .env
php artisan key:generate
touch database/database.sqlite
- name: Lint
run: |
find app plugins config database -name '*.php' -print0 | xargs -0 -n1 php -l
- name: Migrate & Seed (sqlite)
run: php artisan migrate --seed --force
- name: Run tests (sqlite)
run: php artisan test
# 生产走 MySQL:可选并行 MySQL 测试
- name: Run tests (mysql)
env:
DB_CONNECTION: mysql
DB_HOST: 127.0.0.1
DB_PORT: 3306
DB_DATABASE: laralog_test
DB_USERNAME: root
DB_PASSWORD: root
run: php artisan test
# 生产部署示例(SSH + rsync)。真实环境按需开启并配置 secrets:
# DEPLOY_HOST / DEPLOY_USER / DEPLOY_PATH / DEPLOY_SSH_KEY
deploy:
if: github.ref == 'refs/heads/main'
needs: test
runs-on: ubuntu-latest
environment: production
steps:
- uses: actions/checkout@v4
- name: Deploy via SSH
uses: appleboy/ssh-action@v1
with:
host: ${{ secrets.DEPLOY_HOST }}
username: ${{ secrets.DEPLOY_USER }}
key: ${{ secrets.DEPLOY_SSH_KEY }}
script: |
cd ${{ secrets.DEPLOY_PATH }}
git pull origin main
composer install --no-dev --no-interaction --prefer-dist
php artisan migrate --force
php artisan config:cache
php artisan route:cache
php artisan view:cache
php artisan theme:publish
pm2 restart laralog-workerman laralog-schedule || pm2 start ecosystem.config.js
+6
View File
@@ -101,6 +101,12 @@ php artisan workerman:serve stop
- 失败重试:`WORKERMAN_MAX_TRIES`(默认 3),超时 `WORKERMAN_TIMEOUT`(默认 60s),重试耗尽进 `failed_jobs` - 失败重试:`WORKERMAN_MAX_TRIES`(默认 3),超时 `WORKERMAN_TIMEOUT`(默认 60s),重试耗尽进 `failed_jobs`
- 降级路径:`php artisan queue:work` 照常可用(同一队列) - 降级路径:`php artisan queue:work` 照常可用(同一队列)
## 对外 API
- 交互式文档(OpenAPI/Swagger 风格):`GET /docs/api`
- 端点:`/api/site``/api/posts``/api/posts/{slug}``/api/categories``/api/tags``POST /api/comments``/api/me`Bearer Token
- 供小程序 / 第三方平台接入,详见 `docs/api.md`
## 测试 ## 测试
```bash ```bash
@@ -1,5 +1,8 @@
<?php <?php
declare(strict_types=1);
namespace App\Blog\Controllers; namespace App\Blog\Controllers;
use App\Models\Post; use App\Models\Post;
+3
View File
@@ -1,5 +1,8 @@
<?php <?php
declare(strict_types=1);
namespace App\Blog\Controllers; namespace App\Blog\Controllers;
use App\Models\User; use App\Models\User;
@@ -1,5 +1,8 @@
<?php <?php
declare(strict_types=1);
namespace App\Blog\Controllers; namespace App\Blog\Controllers;
use App\Models\Category; use App\Models\Category;
@@ -1,5 +1,8 @@
<?php <?php
declare(strict_types=1);
namespace App\Blog\Controllers; namespace App\Blog\Controllers;
use App\Models\Comment; use App\Models\Comment;
+3
View File
@@ -1,5 +1,8 @@
<?php <?php
declare(strict_types=1);
namespace App\Blog\Controllers; namespace App\Blog\Controllers;
class Controller class Controller
+3
View File
@@ -1,5 +1,8 @@
<?php <?php
declare(strict_types=1);
namespace App\Blog\Controllers; namespace App\Blog\Controllers;
use App\Models\Post; use App\Models\Post;
+3
View File
@@ -1,5 +1,8 @@
<?php <?php
declare(strict_types=1);
namespace App\Blog\Controllers; namespace App\Blog\Controllers;
use App\Models\Post; use App\Models\Post;
@@ -1,5 +1,8 @@
<?php <?php
declare(strict_types=1);
namespace App\Blog\Controllers; namespace App\Blog\Controllers;
use App\Models\Category; use App\Models\Category;
+3
View File
@@ -1,5 +1,8 @@
<?php <?php
declare(strict_types=1);
namespace App\Blog\Controllers; namespace App\Blog\Controllers;
use App\Models\Link; use App\Models\Link;
+3
View File
@@ -1,5 +1,8 @@
<?php <?php
declare(strict_types=1);
namespace App\Blog\Controllers; namespace App\Blog\Controllers;
use App\Blog\Services\PostContentRenderer; use App\Blog\Services\PostContentRenderer;
@@ -1,5 +1,8 @@
<?php <?php
declare(strict_types=1);
namespace App\Blog\Controllers; namespace App\Blog\Controllers;
use App\Models\Post; use App\Models\Post;
+3
View File
@@ -1,5 +1,8 @@
<?php <?php
declare(strict_types=1);
namespace App\Blog\Controllers; namespace App\Blog\Controllers;
use App\Models\Post; use App\Models\Post;
@@ -1,5 +1,8 @@
<?php <?php
declare(strict_types=1);
namespace App\Blog\Controllers; namespace App\Blog\Controllers;
use App\Blog\Support\ThemeManager; use App\Blog\Support\ThemeManager;
+3
View File
@@ -1,5 +1,8 @@
<?php <?php
declare(strict_types=1);
namespace App\Blog\Jobs; namespace App\Blog\Jobs;
use App\Blog\Services\LlmClient; use App\Blog\Services\LlmClient;
@@ -1,5 +1,8 @@
<?php <?php
declare(strict_types=1);
namespace App\Blog\Providers; namespace App\Blog\Providers;
use App\Blog\Support\PluginManager; use App\Blog\Support\PluginManager;
@@ -1,5 +1,8 @@
<?php <?php
declare(strict_types=1);
namespace App\Blog\Providers; namespace App\Blog\Providers;
use App\Blog\Support\ThemeManager; use App\Blog\Support\ThemeManager;
+3
View File
@@ -1,5 +1,8 @@
<?php <?php
declare(strict_types=1);
namespace App\Blog\Services; namespace App\Blog\Services;
use App\Models\Post; use App\Models\Post;
+3
View File
@@ -1,5 +1,8 @@
<?php <?php
declare(strict_types=1);
namespace App\Blog\Services; namespace App\Blog\Services;
use Illuminate\Support\Facades\Http; use Illuminate\Support\Facades\Http;
+3
View File
@@ -1,5 +1,8 @@
<?php <?php
declare(strict_types=1);
namespace App\Blog\Services; namespace App\Blog\Services;
use Illuminate\Support\Facades\Http; use Illuminate\Support\Facades\Http;
+3
View File
@@ -1,5 +1,8 @@
<?php <?php
declare(strict_types=1);
namespace App\Blog\Services; namespace App\Blog\Services;
use App\Blog\Support\PluginManager; use App\Blog\Support\PluginManager;
@@ -1,5 +1,8 @@
<?php <?php
declare(strict_types=1);
namespace App\Blog\Services; namespace App\Blog\Services;
use App\Models\Post; use App\Models\Post;
+3
View File
@@ -1,5 +1,8 @@
<?php <?php
declare(strict_types=1);
namespace App\Blog\Support; namespace App\Blog\Support;
use App\Models\PluginRecord; use App\Models\PluginRecord;
+3
View File
@@ -1,5 +1,8 @@
<?php <?php
declare(strict_types=1);
namespace App\Blog\Support; namespace App\Blog\Support;
/** /**
@@ -1,5 +1,8 @@
<?php <?php
declare(strict_types=1);
namespace App\Blog\Support; namespace App\Blog\Support;
use Illuminate\Support\Facades\Route; use Illuminate\Support\Facades\Route;
+3
View File
@@ -1,5 +1,8 @@
<?php <?php
declare(strict_types=1);
namespace App\Blog\Support; namespace App\Blog\Support;
use App\Models\Setting; use App\Models\Setting;
@@ -1,5 +1,8 @@
<?php <?php
declare(strict_types=1);
namespace App\Blog\Support; namespace App\Blog\Support;
use Workerman\Connection\TcpConnection; use Workerman\Connection\TcpConnection;
@@ -1,5 +1,8 @@
<?php <?php
declare(strict_types=1);
namespace App\Blog\View\Composers; namespace App\Blog\View\Composers;
use App\Models\Category; use App\Models\Category;
@@ -1,5 +1,8 @@
<?php <?php
declare(strict_types=1);
namespace App\Console\Commands; namespace App\Console\Commands;
use App\Support\MediaDisk; use App\Support\MediaDisk;
+3
View File
@@ -1,5 +1,8 @@
<?php <?php
declare(strict_types=1);
namespace App\Console\Commands; namespace App\Console\Commands;
use App\Models\Post; use App\Models\Post;
+3
View File
@@ -1,5 +1,8 @@
<?php <?php
declare(strict_types=1);
namespace App\Console\Commands; namespace App\Console\Commands;
use App\Blog\Services\AttachmentImporter; use App\Blog\Services\AttachmentImporter;
+3
View File
@@ -1,5 +1,8 @@
<?php <?php
declare(strict_types=1);
namespace App\Console\Commands; namespace App\Console\Commands;
use App\Blog\Support\ThemeManager; use App\Blog\Support\ThemeManager;
+3
View File
@@ -1,5 +1,8 @@
<?php <?php
declare(strict_types=1);
namespace App\Console\Commands; namespace App\Console\Commands;
use Illuminate\Console\Command; use Illuminate\Console\Command;
+3
View File
@@ -1,5 +1,8 @@
<?php <?php
declare(strict_types=1);
namespace App\Filament\Pages; namespace App\Filament\Pages;
use App\Models\Setting; use App\Models\Setting;
+3
View File
@@ -1,5 +1,8 @@
<?php <?php
declare(strict_types=1);
namespace App\Filament\Pages; namespace App\Filament\Pages;
use App\Blog\Services\MarketplaceClient; use App\Blog\Services\MarketplaceClient;
+3
View File
@@ -1,5 +1,8 @@
<?php <?php
declare(strict_types=1);
namespace App\Filament\Pages; namespace App\Filament\Pages;
use App\Blog\Services\PackageInstaller; use App\Blog\Services\PackageInstaller;
@@ -1,5 +1,8 @@
<?php <?php
declare(strict_types=1);
namespace App\Filament\Resources\Categories; namespace App\Filament\Resources\Categories;
use App\Filament\Resources\Categories\Pages\CreateCategory; use App\Filament\Resources\Categories\Pages\CreateCategory;
@@ -1,5 +1,8 @@
<?php <?php
declare(strict_types=1);
namespace App\Filament\Resources\Categories\Pages; namespace App\Filament\Resources\Categories\Pages;
use App\Filament\Resources\Categories\CategoryResource; use App\Filament\Resources\Categories\CategoryResource;
@@ -1,5 +1,8 @@
<?php <?php
declare(strict_types=1);
namespace App\Filament\Resources\Categories\Pages; namespace App\Filament\Resources\Categories\Pages;
use App\Filament\Resources\Categories\CategoryResource; use App\Filament\Resources\Categories\CategoryResource;
@@ -1,5 +1,8 @@
<?php <?php
declare(strict_types=1);
namespace App\Filament\Resources\Categories\Pages; namespace App\Filament\Resources\Categories\Pages;
use App\Filament\Resources\Categories\CategoryResource; use App\Filament\Resources\Categories\CategoryResource;
@@ -1,5 +1,8 @@
<?php <?php
declare(strict_types=1);
namespace App\Filament\Resources\Categories\Schemas; namespace App\Filament\Resources\Categories\Schemas;
use Filament\Forms\Components\TextInput; use Filament\Forms\Components\TextInput;
@@ -1,5 +1,8 @@
<?php <?php
declare(strict_types=1);
namespace App\Filament\Resources\Categories\Tables; namespace App\Filament\Resources\Categories\Tables;
use Filament\Actions\BulkActionGroup; use Filament\Actions\BulkActionGroup;
@@ -1,5 +1,8 @@
<?php <?php
declare(strict_types=1);
namespace App\Filament\Resources\Comments; namespace App\Filament\Resources\Comments;
use App\Filament\Resources\Comments\Pages\CreateComment; use App\Filament\Resources\Comments\Pages\CreateComment;
@@ -1,5 +1,8 @@
<?php <?php
declare(strict_types=1);
namespace App\Filament\Resources\Comments\Pages; namespace App\Filament\Resources\Comments\Pages;
use App\Filament\Resources\Comments\CommentResource; use App\Filament\Resources\Comments\CommentResource;
@@ -1,5 +1,8 @@
<?php <?php
declare(strict_types=1);
namespace App\Filament\Resources\Comments\Pages; namespace App\Filament\Resources\Comments\Pages;
use App\Filament\Resources\Comments\CommentResource; use App\Filament\Resources\Comments\CommentResource;
@@ -1,5 +1,8 @@
<?php <?php
declare(strict_types=1);
namespace App\Filament\Resources\Comments\Pages; namespace App\Filament\Resources\Comments\Pages;
use App\Filament\Resources\Comments\CommentResource; use App\Filament\Resources\Comments\CommentResource;
@@ -1,5 +1,8 @@
<?php <?php
declare(strict_types=1);
namespace App\Filament\Resources\Comments\Schemas; namespace App\Filament\Resources\Comments\Schemas;
use Filament\Forms\Components\Select; use Filament\Forms\Components\Select;
@@ -1,5 +1,8 @@
<?php <?php
declare(strict_types=1);
namespace App\Filament\Resources\Comments\Tables; namespace App\Filament\Resources\Comments\Tables;
use App\Models\Comment; use App\Models\Comment;
@@ -1,5 +1,8 @@
<?php <?php
declare(strict_types=1);
namespace App\Filament\Resources\Links; namespace App\Filament\Resources\Links;
use App\Filament\Resources\Links\Pages\CreateLink; use App\Filament\Resources\Links\Pages\CreateLink;
@@ -1,5 +1,8 @@
<?php <?php
declare(strict_types=1);
namespace App\Filament\Resources\Links\Pages; namespace App\Filament\Resources\Links\Pages;
use App\Filament\Resources\Links\LinkResource; use App\Filament\Resources\Links\LinkResource;
@@ -1,5 +1,8 @@
<?php <?php
declare(strict_types=1);
namespace App\Filament\Resources\Links\Pages; namespace App\Filament\Resources\Links\Pages;
use App\Filament\Resources\Links\LinkResource; use App\Filament\Resources\Links\LinkResource;
@@ -1,5 +1,8 @@
<?php <?php
declare(strict_types=1);
namespace App\Filament\Resources\Links\Pages; namespace App\Filament\Resources\Links\Pages;
use App\Filament\Resources\Links\LinkResource; use App\Filament\Resources\Links\LinkResource;
@@ -1,5 +1,8 @@
<?php <?php
declare(strict_types=1);
namespace App\Filament\Resources\Links\Schemas; namespace App\Filament\Resources\Links\Schemas;
use Filament\Forms\Components\TextInput; use Filament\Forms\Components\TextInput;
@@ -1,5 +1,8 @@
<?php <?php
declare(strict_types=1);
namespace App\Filament\Resources\Links\Tables; namespace App\Filament\Resources\Links\Tables;
use Filament\Actions\BulkActionGroup; use Filament\Actions\BulkActionGroup;
@@ -1,5 +1,8 @@
<?php <?php
declare(strict_types=1);
namespace App\Filament\Resources\Media; namespace App\Filament\Resources\Media;
use App\Filament\Resources\Media\Pages\CreateMedia; use App\Filament\Resources\Media\Pages\CreateMedia;
@@ -1,5 +1,8 @@
<?php <?php
declare(strict_types=1);
namespace App\Filament\Resources\Media\Pages; namespace App\Filament\Resources\Media\Pages;
use App\Filament\Resources\Media\MediaResource; use App\Filament\Resources\Media\MediaResource;
@@ -1,5 +1,8 @@
<?php <?php
declare(strict_types=1);
namespace App\Filament\Resources\Media\Pages; namespace App\Filament\Resources\Media\Pages;
use App\Filament\Resources\Media\MediaResource; use App\Filament\Resources\Media\MediaResource;
@@ -1,5 +1,8 @@
<?php <?php
declare(strict_types=1);
namespace App\Filament\Resources\Media\Pages; namespace App\Filament\Resources\Media\Pages;
use App\Filament\Resources\Media\MediaResource; use App\Filament\Resources\Media\MediaResource;
@@ -1,5 +1,8 @@
<?php <?php
declare(strict_types=1);
namespace App\Filament\Resources\Media\Schemas; namespace App\Filament\Resources\Media\Schemas;
use Filament\Schemas\Schema; use Filament\Schemas\Schema;
@@ -1,5 +1,8 @@
<?php <?php
declare(strict_types=1);
namespace App\Filament\Resources\Media\Tables; namespace App\Filament\Resources\Media\Tables;
use Filament\Actions\BulkActionGroup; use Filament\Actions\BulkActionGroup;
@@ -1,5 +1,8 @@
<?php <?php
declare(strict_types=1);
namespace App\Filament\Resources\Posts\Pages; namespace App\Filament\Resources\Posts\Pages;
use App\Filament\Resources\Posts\PostResource; use App\Filament\Resources\Posts\PostResource;
@@ -1,5 +1,8 @@
<?php <?php
declare(strict_types=1);
namespace App\Filament\Resources\Posts\Pages; namespace App\Filament\Resources\Posts\Pages;
use App\Filament\Resources\Posts\PostResource; use App\Filament\Resources\Posts\PostResource;
@@ -1,5 +1,8 @@
<?php <?php
declare(strict_types=1);
namespace App\Filament\Resources\Posts\Pages; namespace App\Filament\Resources\Posts\Pages;
use App\Filament\Resources\Posts\PostResource; use App\Filament\Resources\Posts\PostResource;
@@ -1,5 +1,8 @@
<?php <?php
declare(strict_types=1);
namespace App\Filament\Resources\Posts; namespace App\Filament\Resources\Posts;
use App\Filament\Resources\Posts\Pages\CreatePost; use App\Filament\Resources\Posts\Pages\CreatePost;
@@ -1,5 +1,8 @@
<?php <?php
declare(strict_types=1);
namespace App\Filament\Resources\Posts\Schemas; namespace App\Filament\Resources\Posts\Schemas;
use App\Support\MediaDisk; use App\Support\MediaDisk;
@@ -1,5 +1,8 @@
<?php <?php
declare(strict_types=1);
namespace App\Filament\Resources\Posts\Tables; namespace App\Filament\Resources\Posts\Tables;
use Filament\Actions\BulkActionGroup; use Filament\Actions\BulkActionGroup;
@@ -1,5 +1,8 @@
<?php <?php
declare(strict_types=1);
namespace App\Filament\Resources\Users\Pages; namespace App\Filament\Resources\Users\Pages;
use App\Filament\Resources\Users\UserResource; use App\Filament\Resources\Users\UserResource;
@@ -1,5 +1,8 @@
<?php <?php
declare(strict_types=1);
namespace App\Filament\Resources\Users\Pages; namespace App\Filament\Resources\Users\Pages;
use App\Filament\Resources\Users\UserResource; use App\Filament\Resources\Users\UserResource;
@@ -1,5 +1,8 @@
<?php <?php
declare(strict_types=1);
namespace App\Filament\Resources\Users\Pages; namespace App\Filament\Resources\Users\Pages;
use App\Filament\Resources\Users\UserResource; use App\Filament\Resources\Users\UserResource;
@@ -1,5 +1,8 @@
<?php <?php
declare(strict_types=1);
namespace App\Filament\Resources\Users\Schemas; namespace App\Filament\Resources\Users\Schemas;
use Filament\Forms\Components\DateTimePicker; use Filament\Forms\Components\DateTimePicker;
@@ -1,5 +1,8 @@
<?php <?php
declare(strict_types=1);
namespace App\Filament\Resources\Users\Tables; namespace App\Filament\Resources\Users\Tables;
use Filament\Actions\BulkActionGroup; use Filament\Actions\BulkActionGroup;
@@ -1,5 +1,8 @@
<?php <?php
declare(strict_types=1);
namespace App\Filament\Resources\Users; namespace App\Filament\Resources\Users;
use App\Filament\Resources\Users\Pages\CreateUser; use App\Filament\Resources\Users\Pages\CreateUser;
+3
View File
@@ -1,5 +1,8 @@
<?php <?php
declare(strict_types=1);
namespace App\Filament\Widgets; namespace App\Filament\Widgets;
use App\Models\Comment; use App\Models\Comment;
+3
View File
@@ -1,5 +1,8 @@
<?php <?php
declare(strict_types=1);
namespace App\Filament\Widgets; namespace App\Filament\Widgets;
use App\Models\Comment; use App\Models\Comment;
+243
View File
@@ -0,0 +1,243 @@
<?php
declare(strict_types=1);
namespace App\Http\Controllers\Api;
use App\Blog\Services\PostContentRenderer;
use App\Models\Category;
use App\Models\Comment;
use App\Models\Post;
use App\Models\Setting;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
use Spatie\Tags\Tag;
/**
* 对外 API:为小程序/第三方平台提供数据与评论能力。
*/
class ApiController extends Controller
{
/**
* 站点信息。
*
* @response array{name: string, description: string, icp: string, url: string}
*/
public function site(): JsonResponse
{
return response()->json([
'name' => Setting::get('site_name', config('blog.name')),
'description' => Setting::get('site_description', config('blog.description')),
'icp' => Setting::get('site_icp', config('blog.icp')),
'url' => url('/'),
'rss' => route('feed.rss'),
'api_version' => '1.0',
]);
}
/**
* 文章列表(分页)。
*
* @queryParam page int 页码 Example: 1
* @queryParam per_page int 每页数量(默认 10,最大 50Example: 10
* @queryParam category string 分类 slug Example: tech
* @queryParam tag string 标签名 Example: laravel
* @queryParam q string 关键词搜索 Example: laravel
*
* @response array{data: array, meta: array}
*/
public function posts(Request $request): JsonResponse
{
$query = Post::published()->with('category:id,name,slug')->with('tags:id,name');
if ($category = $request->query('category')) {
$query->whereHas('category', fn ($q) => $q->where('slug', $category)->orWhere('name', $category));
}
if ($tag = $request->query('tag')) {
$query->whereHas('tags', fn ($q) => $q->where('name', $tag)->orWhere('slug', $tag));
}
if ($q = trim((string) $request->query('q', ''))) {
$query->search($q);
}
$perPage = min((int) $request->query('per_page', 10), 50);
$posts = $query->orderByDesc('published_at')->paginate($perPage);
return response()->json([
'data' => $posts->through(fn (Post $post) => $this->postSummary($post))->items(),
'meta' => [
'current_page' => $posts->currentPage(),
'last_page' => $posts->lastPage(),
'per_page' => $posts->perPage(),
'total' => $posts->total(),
],
]);
}
/**
* 文章详情。
*
* @urlParam slug string required 文章 slug ID Example: post-1
*
* @response array{id: int, title: string, content_html: string, ...}
*/
public function post(string $slug): JsonResponse
{
$post = Post::query()
->where('slug', $slug)
->orWhere('id', (int) $slug)
->first();
abort_unless($post && $post->status === 'published', 404);
// 会员/付费内容过滤与前台一致
$contentHtml = app(PostContentRenderer::class)->render($post);
return response()->json([
'id' => $post->id,
'title' => $post->title,
'slug' => $post->slug,
'excerpt' => $post->excerpt_or_fallback,
'content_html' => $contentHtml,
'content_format' => $post->content_format,
'keywords' => $post->keywords,
'category' => $post->category ? ['id' => $post->category->id, 'name' => $post->category->name, 'slug' => $post->category->slug] : null,
'tags' => $post->tags->map(fn ($t) => ['id' => $t->id, 'name' => $t->name, 'slug' => $t->slug])->values(),
'views' => $post->views,
'comment_count' => $post->comment_count,
'published_at' => $post->published_at?->toIso8601String(),
'url' => route('posts.show', $post->slug ?: $post->id),
]);
}
/**
* 分类列表。
*
* @response array{data: array}
*/
public function categories(): JsonResponse
{
return response()->json([
'data' => Category::query()->orderBy('display_order')->orderBy('name')->get(['id', 'name', 'slug', 'post_count']),
]);
}
/**
* 标签列表。
*
* @response array{data: array}
*/
public function tags(): JsonResponse
{
$counts = DB::table('taggables')
->selectRaw('tag_id, COUNT(*) as total')
->where('taggable_type', Post::class)
->groupBy('tag_id')
->pluck('total', 'tag_id');
return response()->json([
'data' => Tag::query()->where('type', 'post')->get()
->map(fn (Tag $tag) => [
'id' => $tag->id,
'name' => $tag->name,
'slug' => $tag->slug,
'post_count' => (int) ($counts[$tag->id] ?? 0),
])
->values(),
]);
}
/**
* 提交评论(公开)。
*
* @bodyParam author_name string required 昵称 Example: 访客
* @bodyParam author_email string 邮箱 Example: guest@example.com
* @bodyParam author_url string 网站 Example: https://example.com
* @bodyParam content string required 评论内容 Example: 写得很好
* @bodyParam website string 蜜罐字段,留空 Example:
*/
public function storeComment(Request $request): JsonResponse
{
$data = $request->validate([
'post_id' => ['required', 'integer', 'exists:posts,id'],
'author_name' => ['required', 'string', 'max:50'],
'author_email' => ['nullable', 'email', 'max:255'],
'author_url' => ['nullable', 'url', 'max:255'],
'content' => ['required', 'string', 'min:'.(int) Setting::get('comment_min_len', 2), 'max:'.(int) Setting::get('comment_max_len', 6000)],
]);
// 蜜罐
if ($request->filled('website')) {
return response()->json(['message' => '提交失败'], 422);
}
$post = Post::findOrFail((int) $data['post_id']);
if ($post->status !== 'published' || $post->close_comment) {
return response()->json(['message' => '该文章不允许评论'], 422);
}
$status = (int) Setting::get('comment_audit', 0) === 1 ? 'pending' : 'published';
$comment = $post->comments()->create([
'user_id' => $request->user()?->id,
'author_name' => $data['author_name'],
'author_email' => $data['author_email'] ?? null,
'author_url' => $data['author_url'] ?? null,
'content' => $data['content'],
'ip' => $request->ip(),
'status' => $status,
]);
if ($status === 'published') {
$post->increment('comment_count');
}
app(\App\Blog\Support\PluginManager::class)->doAction('comment.created', $comment);
return response()->json([
'message' => $status === 'published' ? '评论已发布' : '评论已提交,等待审核',
'data' => ['id' => $comment->id, 'status' => $status],
], 201);
}
/**
* 当前登录用户(需 Bearer Token)。
*
* @authenticated
*
* @response array{id: int, name: string, email: string, roles: array}
*/
public function me(Request $request): JsonResponse
{
$user = $request->user();
return response()->json([
'id' => $user->id,
'name' => $user->name,
'email' => $user->email,
'roles' => $user->getRoleNames(),
'url' => $user->url,
]);
}
private function postSummary(Post $post): array
{
return [
'id' => $post->id,
'title' => $post->title,
'slug' => $post->slug,
'excerpt' => $post->excerpt_or_fallback,
'category' => $post->category?->name,
'tags' => $post->tags->pluck('name')->values(),
'views' => $post->views,
'comment_count' => $post->comment_count,
'published_at' => $post->published_at?->toIso8601String(),
'url' => route('posts.show', $post->slug ?: $post->id),
];
}
}
+9
View File
@@ -0,0 +1,9 @@
<?php
declare(strict_types=1);
namespace App\Http\Controllers\Api;
abstract class Controller
{
}
+3
View File
@@ -1,5 +1,8 @@
<?php <?php
declare(strict_types=1);
namespace App\Http\Controllers; namespace App\Http\Controllers;
abstract class Controller abstract class Controller
+3
View File
@@ -1,5 +1,8 @@
<?php <?php
declare(strict_types=1);
namespace App\Models; namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Factories\HasFactory;
+3
View File
@@ -1,5 +1,8 @@
<?php <?php
declare(strict_types=1);
namespace App\Models; namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Factories\HasFactory;
+3
View File
@@ -1,5 +1,8 @@
<?php <?php
declare(strict_types=1);
namespace App\Models; namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Factories\HasFactory;
+3
View File
@@ -1,5 +1,8 @@
<?php <?php
declare(strict_types=1);
namespace App\Models; namespace App\Models;
use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Model;
+3
View File
@@ -1,5 +1,8 @@
<?php <?php
declare(strict_types=1);
namespace App\Models; namespace App\Models;
use Illuminate\Database\Eloquent\Builder; use Illuminate\Database\Eloquent\Builder;
+3
View File
@@ -1,5 +1,8 @@
<?php <?php
declare(strict_types=1);
namespace App\Models; namespace App\Models;
use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Model;
+5 -1
View File
@@ -1,5 +1,8 @@
<?php <?php
declare(strict_types=1);
namespace App\Models; namespace App\Models;
use Database\Factories\UserFactory; use Database\Factories\UserFactory;
@@ -9,13 +12,14 @@ use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Relations\HasMany; use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Foundation\Auth\User as Authenticatable; use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable; use Illuminate\Notifications\Notifiable;
use Laravel\Sanctum\HasApiTokens;
use Illuminate\Support\Facades\Hash; use Illuminate\Support\Facades\Hash;
use Spatie\Permission\Traits\HasRoles; use Spatie\Permission\Traits\HasRoles;
class User extends Authenticatable implements FilamentUser class User extends Authenticatable implements FilamentUser
{ {
/** @use HasFactory<UserFactory> */ /** @use HasFactory<UserFactory> */
use HasFactory, Notifiable, HasRoles; use HasFactory, Notifiable, HasRoles, HasApiTokens;
public function canAccessPanel(Panel $panel): bool public function canAccessPanel(Panel $panel): bool
{ {
+3
View File
@@ -1,5 +1,8 @@
<?php <?php
declare(strict_types=1);
namespace App\Providers; namespace App\Providers;
use Illuminate\Support\ServiceProvider; use Illuminate\Support\ServiceProvider;
@@ -1,5 +1,8 @@
<?php <?php
declare(strict_types=1);
namespace App\Providers\Filament; namespace App\Providers\Filament;
use App\Filament\Pages\BlogSettings; use App\Filament\Pages\BlogSettings;
+3
View File
@@ -1,5 +1,8 @@
<?php <?php
declare(strict_types=1);
namespace App\Support; namespace App\Support;
class MediaDisk class MediaDisk
+3
View File
@@ -1,5 +1,8 @@
<?php <?php
declare(strict_types=1);
namespace App\Support; namespace App\Support;
use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\DB;
+3
View File
@@ -1,5 +1,8 @@
<?php <?php
declare(strict_types=1);
use App\Blog\Support\ThemeManager; use App\Blog\Support\ThemeManager;
if (! function_exists('theme_view')) { if (! function_exists('theme_view')) {
+1
View File
@@ -7,6 +7,7 @@ use Illuminate\Foundation\Configuration\Middleware;
return Application::configure(basePath: dirname(__DIR__)) return Application::configure(basePath: dirname(__DIR__))
->withRouting( ->withRouting(
web: __DIR__.'/../routes/web.php', web: __DIR__.'/../routes/web.php',
api: __DIR__.'/../routes/api.php',
commands: __DIR__.'/../routes/console.php', commands: __DIR__.'/../routes/console.php',
health: '/up', health: '/up',
) )
+2
View File
@@ -7,9 +7,11 @@
"license": "MIT", "license": "MIT",
"require": { "require": {
"php": "^8.2", "php": "^8.2",
"dedoc/scramble": "^0.13.39",
"filament/filament": "^5.7", "filament/filament": "^5.7",
"filament/spatie-laravel-media-library-plugin": "^5.7", "filament/spatie-laravel-media-library-plugin": "^5.7",
"laravel/framework": "^12.0", "laravel/framework": "^12.0",
"laravel/sanctum": "^4.0",
"laravel/tinker": "^2.10.1", "laravel/tinker": "^2.10.1",
"league/commonmark": "^2.9", "league/commonmark": "^2.9",
"league/flysystem-aws-s3-v3": "^3.35", "league/flysystem-aws-s3-v3": "^3.35",
Generated
+252 -61
View File
@@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically" "This file is @generated automatically"
], ],
"content-hash": "3b5974911686ef4cf9590ee3210822a5", "content-hash": "aaa7f930f1c6d7bbf959e9b5bcdac929",
"packages": [ "packages": [
{ {
"name": "anourvalar/eloquent-serialize", "name": "anourvalar/eloquent-serialize",
@@ -845,6 +845,87 @@
], ],
"time": "2026-08-06T08:41:51+00:00" "time": "2026-08-06T08:41:51+00:00"
}, },
{
"name": "dedoc/scramble",
"version": "v0.13.39",
"source": {
"type": "git",
"url": "https://github.com/dedoc/scramble.git",
"reference": "7fcc4758d62f22d326637a578168bd5eb67a8625"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/dedoc/scramble/zipball/7fcc4758d62f22d326637a578168bd5eb67a8625",
"reference": "7fcc4758d62f22d326637a578168bd5eb67a8625",
"shasum": ""
},
"require": {
"illuminate/contracts": "^10.0|^11.0|^12.0|^13.0",
"myclabs/deep-copy": "^1.12",
"nikic/php-parser": "^5.0",
"php": "^8.1",
"phpstan/phpdoc-parser": "^1.0|^2.0",
"spatie/laravel-package-tools": "^1.9.2"
},
"require-dev": {
"larastan/larastan": "^3.3",
"laravel/pint": "^v1.1.0",
"laravel/scout": "^10.0|^11.0",
"nunomaduro/collision": "^7.0|^8.0",
"orchestra/testbench": "^8.0|^9.0|^10.0|^11.0",
"pestphp/pest": "^2.34|^3.7|^4.4",
"pestphp/pest-plugin-laravel": "^2.3|^3.1|^4.1",
"phpstan/extension-installer": "^1.4",
"phpstan/phpstan-deprecation-rules": "^2.0",
"phpstan/phpstan-phpunit": "^2.0",
"phpunit/phpunit": "^10.5|^11.5.3|^12.5.12",
"spatie/laravel-permission": "^6.10|^7.2",
"spatie/pest-plugin-snapshots": "^2.1"
},
"type": "library",
"extra": {
"laravel": {
"providers": [
"Dedoc\\Scramble\\ScrambleServiceProvider"
]
}
},
"autoload": {
"psr-4": {
"Dedoc\\Scramble\\": "src",
"Dedoc\\Scramble\\Database\\Factories\\": "database/factories"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Roman Lytvynenko",
"email": "litvinenko95@gmail.com",
"role": "Developer"
}
],
"description": "Automatic generation of API documentation for Laravel applications.",
"homepage": "https://github.com/dedoc/scramble",
"keywords": [
"documentation",
"laravel",
"openapi"
],
"support": {
"issues": "https://github.com/dedoc/scramble/issues",
"source": "https://github.com/dedoc/scramble/tree/v0.13.39"
},
"funding": [
{
"url": "https://github.com/romalytvynenko",
"type": "github"
}
],
"time": "2026-08-06T06:42:48+00:00"
},
{ {
"name": "dflydev/dot-access-data", "name": "dflydev/dot-access-data",
"version": "v3.0.3", "version": "v3.0.3",
@@ -2636,6 +2717,69 @@
}, },
"time": "2026-08-04T14:50:50+00:00" "time": "2026-08-04T14:50:50+00:00"
}, },
{
"name": "laravel/sanctum",
"version": "v4.3.3",
"source": {
"type": "git",
"url": "https://github.com/laravel/sanctum.git",
"reference": "fee27a573d1a013af3721d86153a65e0b11927e6"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/laravel/sanctum/zipball/fee27a573d1a013af3721d86153a65e0b11927e6",
"reference": "fee27a573d1a013af3721d86153a65e0b11927e6",
"shasum": ""
},
"require": {
"ext-json": "*",
"illuminate/console": "^11.0|^12.0|^13.0",
"illuminate/contracts": "^11.0|^12.0|^13.0",
"illuminate/database": "^11.0|^12.0|^13.0",
"illuminate/support": "^11.0|^12.0|^13.0",
"php": "^8.2",
"symfony/console": "^7.0|^8.0"
},
"require-dev": {
"mockery/mockery": "^1.6",
"orchestra/testbench": "^9.15|^10.8|^11.0",
"phpstan/phpstan": "^1.10"
},
"type": "library",
"extra": {
"laravel": {
"providers": [
"Laravel\\Sanctum\\SanctumServiceProvider"
]
}
},
"autoload": {
"psr-4": {
"Laravel\\Sanctum\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Taylor Otwell",
"email": "taylor@laravel.com"
}
],
"description": "Laravel Sanctum provides a featherweight authentication system for SPAs and simple APIs.",
"keywords": [
"auth",
"laravel",
"sanctum"
],
"support": {
"issues": "https://github.com/laravel/sanctum/issues",
"source": "https://github.com/laravel/sanctum"
},
"time": "2026-06-23T18:26:55+00:00"
},
{ {
"name": "laravel/serializable-closure", "name": "laravel/serializable-closure",
"version": "v2.0.15", "version": "v2.0.15",
@@ -4031,6 +4175,66 @@
}, },
"time": "2026-07-06T18:56:19+00:00" "time": "2026-07-06T18:56:19+00:00"
}, },
{
"name": "myclabs/deep-copy",
"version": "1.13.4",
"source": {
"type": "git",
"url": "https://github.com/myclabs/DeepCopy.git",
"reference": "07d290f0c47959fd5eed98c95ee5602db07e0b6a"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/myclabs/DeepCopy/zipball/07d290f0c47959fd5eed98c95ee5602db07e0b6a",
"reference": "07d290f0c47959fd5eed98c95ee5602db07e0b6a",
"shasum": ""
},
"require": {
"php": "^7.1 || ^8.0"
},
"conflict": {
"doctrine/collections": "<1.6.8",
"doctrine/common": "<2.13.3 || >=3 <3.2.2"
},
"require-dev": {
"doctrine/collections": "^1.6.8",
"doctrine/common": "^2.13.3 || ^3.2.2",
"phpspec/prophecy": "^1.10",
"phpunit/phpunit": "^7.5.20 || ^8.5.23 || ^9.5.13"
},
"type": "library",
"autoload": {
"files": [
"src/DeepCopy/deep_copy.php"
],
"psr-4": {
"DeepCopy\\": "src/DeepCopy/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"description": "Create deep copies (clones) of your objects",
"keywords": [
"clone",
"copy",
"duplicate",
"object",
"object graph"
],
"support": {
"issues": "https://github.com/myclabs/DeepCopy/issues",
"source": "https://github.com/myclabs/DeepCopy/tree/1.13.4"
},
"funding": [
{
"url": "https://tidelift.com/funding/github/packagist/myclabs/deep-copy",
"type": "tidelift"
}
],
"time": "2025-08-01T08:46:24+00:00"
},
{ {
"name": "nesbot/carbon", "name": "nesbot/carbon",
"version": "3.13.2", "version": "3.13.2",
@@ -4803,6 +5007,53 @@
], ],
"time": "2025-12-27T19:41:33+00:00" "time": "2025-12-27T19:41:33+00:00"
}, },
{
"name": "phpstan/phpdoc-parser",
"version": "2.3.3",
"source": {
"type": "git",
"url": "https://github.com/phpstan/phpdoc-parser.git",
"reference": "fb19eedd2bb67ff8cf7a5502ad329e701d6398a3"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/phpstan/phpdoc-parser/zipball/fb19eedd2bb67ff8cf7a5502ad329e701d6398a3",
"reference": "fb19eedd2bb67ff8cf7a5502ad329e701d6398a3",
"shasum": ""
},
"require": {
"php": "^7.4 || ^8.0"
},
"require-dev": {
"doctrine/annotations": "^2.0",
"nikic/php-parser": "^5.3.0",
"php-parallel-lint/php-parallel-lint": "^1.2",
"phpstan/extension-installer": "^1.0",
"phpstan/phpstan": "^2.0",
"phpstan/phpstan-phpunit": "^2.0",
"phpstan/phpstan-strict-rules": "^2.0",
"phpunit/phpunit": "^9.6",
"symfony/process": "^5.2"
},
"type": "library",
"autoload": {
"psr-4": {
"PHPStan\\PhpDocParser\\": [
"src/"
]
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"description": "PHPDoc parser with support for nullable, intersection and generic types",
"support": {
"issues": "https://github.com/phpstan/phpdoc-parser/issues",
"source": "https://github.com/phpstan/phpdoc-parser/tree/2.3.3"
},
"time": "2026-07-08T07:01:06+00:00"
},
{ {
"name": "pragmarx/google2fa", "name": "pragmarx/google2fa",
"version": "v9.0.0", "version": "v9.0.0",
@@ -10946,66 +11197,6 @@
}, },
"time": "2024-05-16T03:13:13+00:00" "time": "2024-05-16T03:13:13+00:00"
}, },
{
"name": "myclabs/deep-copy",
"version": "1.13.4",
"source": {
"type": "git",
"url": "https://github.com/myclabs/DeepCopy.git",
"reference": "07d290f0c47959fd5eed98c95ee5602db07e0b6a"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/myclabs/DeepCopy/zipball/07d290f0c47959fd5eed98c95ee5602db07e0b6a",
"reference": "07d290f0c47959fd5eed98c95ee5602db07e0b6a",
"shasum": ""
},
"require": {
"php": "^7.1 || ^8.0"
},
"conflict": {
"doctrine/collections": "<1.6.8",
"doctrine/common": "<2.13.3 || >=3 <3.2.2"
},
"require-dev": {
"doctrine/collections": "^1.6.8",
"doctrine/common": "^2.13.3 || ^3.2.2",
"phpspec/prophecy": "^1.10",
"phpunit/phpunit": "^7.5.20 || ^8.5.23 || ^9.5.13"
},
"type": "library",
"autoload": {
"files": [
"src/DeepCopy/deep_copy.php"
],
"psr-4": {
"DeepCopy\\": "src/DeepCopy/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"description": "Create deep copies (clones) of your objects",
"keywords": [
"clone",
"copy",
"duplicate",
"object",
"object graph"
],
"support": {
"issues": "https://github.com/myclabs/DeepCopy/issues",
"source": "https://github.com/myclabs/DeepCopy/tree/1.13.4"
},
"funding": [
{
"url": "https://tidelift.com/funding/github/packagist/myclabs/deep-copy",
"type": "tidelift"
}
],
"time": "2025-08-01T08:46:24+00:00"
},
{ {
"name": "nunomaduro/collision", "name": "nunomaduro/collision",
"version": "v8.9.5", "version": "v8.9.5",
+3
View File
@@ -1,5 +1,8 @@
<?php <?php
declare(strict_types=1);
return [ return [
/* /*
+3
View File
@@ -1,5 +1,8 @@
<?php <?php
declare(strict_types=1);
use App\Models\User; use App\Models\User;
return [ return [
+3
View File
@@ -1,5 +1,8 @@
<?php <?php
declare(strict_types=1);
return [ return [
'backup' => [ 'backup' => [
+3
View File
@@ -1,5 +1,8 @@
<?php <?php
declare(strict_types=1);
return [ return [
/* /*
+3
View File
@@ -1,5 +1,8 @@
<?php <?php
declare(strict_types=1);
use Illuminate\Support\Str; use Illuminate\Support\Str;
return [ return [
+3
View File
@@ -1,5 +1,8 @@
<?php <?php
declare(strict_types=1);
use Illuminate\Support\Str; use Illuminate\Support\Str;
use Pdo\Mysql; use Pdo\Mysql;

Some files were not shown because too many files have changed in this diff Show More