thesimonharms/lontar 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

thesimonharms/lontar

最新稳定版本:v1.1.2

Composer 安装命令:

composer require thesimonharms/lontar

包简介

A minimal headless blog API package for Laravel with Markdown support.

README 文档

README

A minimal, headless blog API package for Laravel. Ships a Post model, full CRUD controller, and API routes. Stores post bodies as Markdown and renders them server-side via league/commonmark.

No opinions on auth, frontend, or theming — bring your own.

Requirements

  • PHP 8.2+
  • Laravel 11 or 12
  • laravel/sanctum installed in the consuming app (for authenticated endpoints)

Installation

composer require lontar/blog

The service provider is auto-discovered. Run migrations:

php artisan migrate

That's it. The API routes are registered automatically under /api.

Endpoints

Public

Method Endpoint Description
GET /api/posts Paginated list of published posts (title, slug, excerpt, published_at)
GET /api/posts/{slug} Full detail for a single published post

Posts with a null published_at or a future published_at are treated as drafts and excluded from public responses.

Authenticated (auth:sanctum)

Method Endpoint Description
GET /api/posts/drafts Paginated list of unpublished posts
POST /api/posts Create a new post
PUT /api/posts/{slug} Update a post
DELETE /api/posts/{slug} Delete a post
POST /api/posts/{slug}/publish Set published_at to now
POST /api/posts/{slug}/unpublish Set published_at to null

Request Bodies

POST /api/posts

{
    "title": "My Post Title",
    "body": "Markdown content here.",
    "excerpt": "Optional short summary.",
    "published_at": "2026-03-10T00:00:00Z"
}

slug is derived automatically from title. excerpt and published_at are optional — omit published_at to save as a draft.

PUT /api/posts/{slug}

Same fields as above, all optional. If title is updated, slug is regenerated.

Markdown

Post bodies are stored as raw Markdown. The Post model exposes a rendered_body attribute that converts the body to HTML on access via league/commonmark:

$post->rendered_body; // HTML string

Use this in your views when rendering post content. The raw body field is always available too.

Post Model

use Lontar\Blog\Models\Post;

// Published posts
Post::published()->get();

// All posts including drafts
Post::all();

// Find by slug
Post::where('slug', 'my-post')->firstOrFail();

The published scope filters to posts where published_at is not null and not in the future.

Auth

This package ships with auth:sanctum on write routes but does not install or configure Sanctum. Set it up in your consuming app:

composer require laravel/sanctum
php artisan vendor:publish --provider="Laravel\Sanctum\SanctumServiceProvider"
php artisan migrate

Then ensure your api middleware group includes sanctum in bootstrap/app.php or app/Http/Kernel.php.

License

MIT

统计信息

  • 总下载量: 14
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 4
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-03-21

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固