buchin/laravel-ghost
Composer 安装命令:
composer require buchin/laravel-ghost
包简介
👻• A Laravel wrapper that allows you to access Ghost APIs (Content & Admin). Access, create and manage your Ghost content from you app!
README 文档
README
A Laravel wrapper that allows you to access Ghost APIs (Content & Admin). Access, create and manage your Ghost content from you app!
Installation
You can install the package via composer:
composer require igorsgm/laravel-ghost
You can publish the config file with:
php artisan vendor:publish --provider="Igorsgm\Ghost\GhostServiceProvider" --tag="ghost-config"
Usage
Define Ghost API credentials at ghost.php config or in your .env file. i.e.:
GHOST_ADMIN_DOMAIN=https://demo.ghost.io
GHOST_CONTENT_API_KEY=22444f78447824223cefc48062
GHOST_ADMIN_API_KEY=foo:bar
Content API
1) General Usage
// Using the Facade (recommended), which will take the variables from the ghost.php config file $contentApi = Ghost::content(); $response = $contentApi->posts()->all(); // Or you can set the variables manually $contentApi = Ghost::content([ 'key' => '22444f78447824223cefc48062', 'domain' => 'https://demo.ghost.io', 'version' => 4 ]); $response = $contentApi->posts()->all(); $posts = $response->data; $meta = $response->meta;
The Content API for posts, pages, tags, authors, settings, tiers are similiar and can be used with the following methods:
// All resources returned as SuccessResponse (or ErrorResponse) Ghost::content()->posts()->all(); Ghost::content()->authors()->all(); Ghost::content()->tags()->all(); Ghost::content()->pages()->all(); Ghost::content()->settings()->all(); Ghost::content()->tiers()->all();
Single resource returned as Post, Author, Tag, Page or Tier
// Retrieve a single resource by slug Ghost::content()->posts()->fromSlug('welcome'); // Retrieve first resource item Ghost::content()->posts()->first(); // Retrieve a single resource by id Ghost::content()->posts()->find('6285dbba44c5d85187a074ba');
Paginations
// Get paginated resources Ghost::content()->posts()->paginate(); $response = Ghost::content()->posts()->paginate(15); $posts = $response->data; $meta = $response->meta; // Browse between pages $response->getNextPage(); $response->getPreviousPage();
Build your request
Valid for both: Ghost::content() and Ghost::admin() APIs
Ghost::content()->posts() ->include('authors', 'tags') // https://ghost.org/docs/content-api/#include ->fields('title', 'slug', 'html') // https://ghost.org/docs/content-api/#fields ->formats('html') // https://ghost.org/docs/content-api/#formats ->filter('author:john+featured:true') // https://ghost.org/docs/content-api/#filtering ->limit(20) // https://ghost.org/docs/content-api/#limit ->page(2) // https://ghost.org/docs/content-api/#page ->orderBy('title', 'DESC') // https://ghost.org/docs/content-api/#order ->get();
Admin API
- All ContentAPI methods related to Post, Author, Tag, Page or Tier are also available in the Admin API.
| Resource | Methods |
|---|---|
| ->posts() | get, create, update, delete |
| ->pages() | get, create, update, delete |
| ->tags() | get, create, update, delete |
| ->tiers() | get, create, update, delete |
| ->offers() | get, create, update |
| ->members() | get, create, update |
| ->users() | get |
| ->images() | upload |
| ->themes() | upload, activate |
| ->site() | get |
| ->webhooks() | create, update, delete |
(Admin) Posts, Pages, Tags, Tiers, Offers, Members, Users, Webhooks
The consume of these Admin APIs are similar and can be used with the following methods:
// Create post with mobiledoc source Ghost::admin()->posts()->create([ 'title' => 'My Test Post', 'mobiledoc' => '{"version":"0.3.1","atoms":[],"cards":[],"markups":[],"sections":[[1,"p",[[0,[],0,"My post content. Work in progress..."]]]]}', 'status' => 'published', ]); // Create post with HTML source Ghost::admin()->posts()->source('html')->create([ 'title' => 'My Test Post 2', 'html' => '<p>My post content. Work in progress...</p>', 'status' => 'published', ]); // Update resource with mobiledoc source // The updated_at field is required as it is used to handle collision detection, and ensure you’re not overwriting more recent updates. // It is recommended to perform a GET request to fetch the latest data before updating a resource. $post = Ghost::admin()->posts()->find($id); Ghost::admin()->posts()->source('html')->update($id, [ 'title' => 'My New Title', 'html' => '<p>My post content updated. Work in progress...</p>', 'updated_at' => $post->updatedAt, ]); // Delete resource by ID Ghost::admin()->posts()->delete('6285dbba44c5d85187a074ba');
(Admin) Images, Themes
// Upload image $imagePathOrUrl = 'https://picsum.photos/200'; $response = Ghost::admin()->images()->upload($imagePathOrUrl); // Upload theme (.zip) $zipPathOrUrl = 'https://www.learningcontainer.com/wp-content/uploads/2020/05/sample-zip-file.zip'; $response = Ghost::admin()->themes()->upload($zipPathOrUrl); // Activate a theme Ghost::admin()->themes()->activate('theme-name');
Testing
composer test
Changelog
Please see CHANGELOG for more information what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Security
If you discover any security related issues, please email igor.sgm@gmail.com instead of using the issue tracker.
Credits
License
The MIT License (MIT). Please see License File for more information.
buchin/laravel-ghost 适用场景与选型建议
buchin/laravel-ghost 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 897 次下载、GitHub Stars 达 0, 最近一次更新时间为 2025 年 04 月 28 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「blog」 「cms」 「laravel」 「Ghost」 「igorsgm」 「laravel-ghost」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 buchin/laravel-ghost 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 buchin/laravel-ghost 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 buchin/laravel-ghost 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
GraphQL authentication for your headless Craft CMS applications.
Laravel package for opinionated blog implementation
Set Links with a specific language parameter
Supercharged text field validation.
Integrate with Snipcart.
Import an RSS-feed into blog
统计信息
- 总下载量: 897
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 23
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-04-28
