Polyscope——面向 Laravel 的以代理为先的开发环境

Laravel Paper: A Flat-File Eloquent Driver

最后更新于 经过

Laravel Paper: A Flat-File Eloquent Driver image

Laravel Paper , by Jacob Jørgensen , brings Eloquent's feature set to flat-file data sources. It allows you to treat Markdown and JSON files as database records, which is useful for documentation, product catalogs, or small-scale content management where a traditional database might be unnecessary.

Turning Files into Models

By applying the Paper trait and PHP 8 attributes, you can map a model to a specific directory on your disk. You don't need to configure a separate database connection or run migrations to get started:

使用 照亮\数据库\雄辩\模型 ;
使用 JacobJoergensen\LaravelPaper\Attributes\ContentPath ;
使用 JacobJoergensen\LaravelPaper\Attributes\Driver ;
使用 JacobJoergensen\LaravelPaper\Paper ;
#[ 司机 'markdown' )]
#[ ContentPath 'content/docs' )]
班级 文档 延伸 模型
{
使用 Paper ;
}

Querying File Data

Since the driver implements the Eloquent interface, you can use standard query builder methods to filter and sort your files. The slug is derived from the filename automatically, acting as the primary identifier:

// Fetch all documentation pages for a specific version
$docs = 文档 :: 在哪里 '版本' , 'v1.0'
-> orderBy '优先事项' , '升序'
-> 得到 ();
// Retrieve a specific page by its filename
$setup = 文档 :: 寻找 'initial-setup' (英文):
// Search within frontmatter arrays or text
$tagged = 文档 :: whereContains 'labels' , ‘api’ -> 得到 ();
$found = 文档 :: 哪里喜欢 'subtitle' , '%configuration%' -> 得到 ();

File-Based Relationships

The package includes methods for linking different flat-file models. This allows you to define associations based on fields stored in your files' frontmatter:

民众 功能 类别 ()
{
// Resolves based on the 'category_slug' key in the Markdown frontmatter
返回 $this -> belongsToPaper 类别 ::班级 (英文):
}
民众 功能 subPages ()
{
返回 $this -> hasManyPaper 文档 ::班级 (英文):
}

Managing Files through Eloquent

Laravel Paper supports full write capabilities. When you call save() 或者 delete() , the package performs the corresponding filesystem operation, keeping your content in sync with your model state:

// Creating a new file
$doc = 新的 文档 ();
$doc -> 蛞蝓 = 'new-guide' ;
$doc -> 标题 = 'Architecture Overview' ;
$doc -> 内容 = 'Markdown content starts here...' ;
$doc -> 节省 (); // Creates content/docs/new-guide.md
// Deleting an existing file
$outdated = 文档 :: 寻找 'old-api-guide' (英文):
$outdated ?-> 删除 (); // Removes the file from disk

安装

You can add the package to your project via Composer:

作曲家 要求 jacobjoergensen/laravel-paper

Laravel Paper requires PHP 8.4 and Laravel 12.0 or higher. To use the Markdown driver, your files should include YAML frontmatter for metadata:

---
标题 : 架构概述
版本 : v1.0
标签 :[ api , ]
优先事项 : 1
---
Markdown content starts here...

The source code and further documentation for custom drivers are available on GitHub

Yannick Lyn Fatt 的照片

Laravel News 的特约撰稿人和全栈 Web 开发人员。

归档于:
立方体

Laravel 时事通讯

加入超过 4 万名开发者的行列,不错过任何新的技巧、教程等内容。

图像
SerpApi

适用于您的 LLM 和 AI 应用的 Web 搜索 API

访问 SerpApi
Laravel Cloud 标志

Laravel 云

轻松创建和管理服务器,并在几秒钟内部署 Laravel 应用程序。

Laravel 云
SerpApi logo

SerpApi

Access real-time search engine results through a simple API—no more scraping headaches! Use it for AI applications, SEO tools, product research, travel information, and more

SerpApi
鱼叉:新一代时间跟踪和发票标志

Harpoon:新一代时间跟踪和发票系统

新一代时间跟踪和计费软件,帮助您的机构规划和预测盈利的未来。

Harpoon:新一代时间跟踪和发票系统
PhpStorm 标志

PhpStorm

首选的 PHP IDE,对 Laravel 及其生态系统提供广泛的开箱即用支持。

PhpStorm
SaaSykit:Laravel SaaS 入门套件徽标

SaaSykit:Laravel SaaS 入门套件

SaaSykit 是一个多租户 Laravel SaaS 入门套件,包含运行现代 SaaS 所需的所有功能,例如支付、美观的结账界面、管理面板、用户仪表盘、身份验证、现成组件、统计数据、博客、文档等等。

SaaSykit:Laravel SaaS 入门套件
Lucky Media 标志

幸运传媒

Get Lucky Now——拥有十余年经验的 Laravel 开发理想之选!

幸运传媒
了解 Softtech 的标志

了解软科技

Acquaint Softtech 提供 AI 就绪的 Laravel 开发人员,48 小时内即可上手,每月费用为 3000 美元,没有冗长的销售流程,并提供 100% 退款保证。

了解软科技
Kirschbaum 标志

樱桃树

提供创新和稳定性,确保您的Web应用程序取得成功。

樱桃树
绝不妥协标志

绝不妥协

来自 No Compromises 播客的两位经验丰富的开发者 Joel 和 Aaron 现在可以为您的 Laravel 项目提供服务。⬧ 固定费用 9500 美元/月。⬧ 无冗长的销售流程。⬧ 无需签订合同。⬧ 100% 退款保证。

绝不妥协
Tinkerwell 徽标

廷克威尔

Laravel 开发者必备的代码运行器。可在本地和生产环境中体验 AI、自动补全和即时反馈功能。

廷克威尔
Shift 标志

转移

还在运行旧版本的 Laravel?立即实现 Laravel 自动升级和代码现代化,让您的应用程序保持最新状态。

转移
Manage Subscription Plans and Entitlements in Laravel with Laravel Entitlements image

Manage Subscription Plans and Entitlements in Laravel with Laravel Entitlements

阅读文章
Laravel Fluent Validation: An Object-Oriented Rule Builder image

Laravel Fluent Validation: An Object-Oriented Rule Builder

阅读文章
Moat: A Security Review for Your GitHub Account image

Moat: A Security Review for Your GitHub Account

阅读文章
Simple Feature Flags for Laravel with Laravel Toggle image

Simple Feature Flags for Laravel with Laravel Toggle

阅读文章
Manage Laravel Cloud Deployments Inside PhpStorm image

Manage Laravel Cloud Deployments Inside PhpStorm

阅读文章
Piper: Laravel-Style Array and String Helpers for PHP's Pipe Operator image

Piper: Laravel-Style Array and String Helpers for PHP's Pipe Operator

阅读文章