定制 blackpig-creatif/grimoire 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

blackpig-creatif/grimoire

最新稳定版本:v2.0.0

Composer 安装命令:

composer require blackpig-creatif/grimoire

包简介

In-panel documentation for FilamentPHP applications

README 文档

README

Latest Version on Packagist GitHub Tests Action Status GitHub Code Style Action Status Total Downloads

In-panel documentation for FilamentPHP v5 applications.

Grimoire lets you embed rich, versioned documentation directly inside your Filament admin panel. Organise content into Tomes (top-level books) and Chapters (individual pages), author in Markdown with YAML frontmatter, and edit chapters inline without leaving the panel.

Requirements

  • PHP 8.2+
  • Laravel 11 or 12
  • Filament v5

Installation

composer require blackpig-creatif/grimoire

Publish the config (optional):

php artisan vendor:publish --tag="grimoire-config"

Plugin Registration

Register the plugin in your Filament panel provider:

use BlackpigCreatif\Grimoire\GrimoirePlugin;

public function panel(Panel $panel): Panel
{
    return $panel
        ->plugins([
            GrimoirePlugin::make()
                ->navigationGroup('Help')    // optional — defaults to 'Help'
                ->withDocs(),                // optional — enables Grimoire's own built-in docs
        ]);
}

Registering a Tome

A Tome is a top-level documentation section. Register one in your AppServiceProvider::boot():

use BlackpigCreatif\Grimoire\Facades\Grimoire;

Grimoire::registerTome(
    id: 'my-docs',
    label: 'My Documentation',
    icon: 'heroicon-o-book-open',
    path: resource_path('grimoire/my-docs'),
    clusterClass: \App\Filament\Grimoire\Clusters\MyDocsCluster::class,
);

Then scaffold the required Filament stubs:

php artisan grimoire:make-tome my-docs "My Documentation"

Adding Chapters

php artisan grimoire:make-chapter my-docs my-chapter "My Chapter Title"

This generates a Filament page stub and a Markdown file at resources/grimoire/my-docs/my-chapter.md. Add content with YAML frontmatter:

---
title: My Chapter
order: 1
icon: heroicon-o-document-text
---

# My Chapter

Content goes here.

Extending a Tome

Override or add chapters to any Tome (including vendor Tomes) from your app:

Grimoire::extendTome(
    id: 'my-docs',
    path: resource_path('grimoire/my-docs-local'),
);

Local chapters take priority over vendor chapters on slug collision — useful for overriding package documentation with app-specific notes.

Permissions

Access to view and edit documentation is controlled via config/grimoire.php:

'permissions' => [
    'view' => null,   // null = allow all authenticated users (default)
    'edit' => null,   // null = deny all (default)
],

Each key accepts one of the following:

null (default behaviour)

  • view: all authenticated users may read chapters
  • edit: no one may edit chapters

A Laravel Gate ability name

'permissions' => [
    'view' => 'view-docs',
    'edit' => 'edit-docs',
],

Define the ability in AuthServiceProvider (or a dedicated GrimoirePolicy):

Gate::define('view-docs', fn (User $user) => $user->hasRole('staff'));
Gate::define('edit-docs', fn (User $user) => $user->hasRole('admin'));

A Class@method string

'permissions' => [
    'view' => \App\Policies\GrimoirePolicy::class . '@view',
    'edit' => \App\Policies\GrimoirePolicy::class . '@edit',
],

The method receives the authenticated user as its only argument and must return a boolean.

A closure (local development only)

Closures work when config is not cached, making them convenient for local development. They cannot be used in production with php artisan config:cache.

'permissions' => [
    'view' => fn ($user) => true,
    'edit' => fn ($user) => $user->is_admin,
],

Inline Editing

Authenticated users with edit permission can edit chapter content directly in the panel. Click Edit on any chapter page to switch to an inline editor with a Markdown editor for content and a YAML editor for frontmatter.

Locale Support

Grimoire supports two locale strategies for multilingual documentation. Configure in config/grimoire.php:

'locale_strategy' => 'suffix',   // 'suffix' or 'directory'
'fallback_locale'  => 'en',

Suffix strategy — place locale variants alongside the default file:

my-chapter.md       ← locale-neutral fallback
my-chapter.fr.md    ← French
my-chapter.de.md    ← German

Directory strategy — organise by locale subdirectory:

my-chapter.md
fr/my-chapter.md
de/my-chapter.md

Grimoire resolves files in order: current locale → fallback locale → locale-neutral.

Built-in Self-Documentation

Enable Grimoire's own documentation Tome inside your panel with ->withDocs():

GrimoirePlugin::make()->withDocs()

// Or conditionally — e.g. local environment only:
GrimoirePlugin::make()->withDocs(fn ($user) => app()->isLocal())

Caching

For production, cache the navigation tree:

php artisan grimoire:cache
php artisan grimoire:clear-cache

Testing

composer test

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security Vulnerabilities

Please review our security policy on how to report security vulnerabilities.

Credits

License

The MIT License (MIT). Please see License File for more information.

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-02-23

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固