nfragkos/eloquenty
Composer 安装命令:
composer require nfragkos/eloquenty
包简介
Statamic addon that allows you to store specific collection entries into the database via Eloquent.
README 文档
README
This package allows you to store entries for specific collections to the database via Laravel's Eloquent ORM.
Structures are disabled for performance reasons.
Requirements
- PHP 8.2+
- Statamic v5
How it works
Eloquenty uses Statamic Eloquent Driver (https://github.com/statamic/eloquent-driver) but with modifications that allows to use the driver for specific collections entries instead for every entry.
Both standard and Eloquenty collections will be visible under /cp/collections but the Entries column will display the message
"Managed by Eloquenty" for Eloquenty collections.
Eloquenty collections are managed on a separate route /cp/eloquenty/collections which is a clone of /cp/collections route group
with modifications to use the Entry and EntryRepository classes under Eloquenty\Entries that uses Eloquent ORM. The Entry related
classes and Controllers are extending the original Statamic classes.
There's a middleware that redirects from /cp/collections/{collection} to /cp/eloquenty/collections/{collection} when clicking to
view Eloquenty collections under /cp/collections.
Collection modifications should be performed under the original /cp/collections route.
Installation
You can install this package via composer using:
composer require nfragkos/eloquenty
The package will automatically register itself.
Post-Install
-
Publish eloquenty config and migration files:
php artisan vendor:publish --provider="Eloquenty\ServiceProvider" -
Run
php artisan migrateto create Eloquenty table.
(Make sure laravel is configured properly and schema is created. See https://laravel.com/docs/8.x/database#configuration) -
Create a new collection or enter existing collection handle in config/eloquenty.php:
'collections' => [ 'blog', ],
This means that the entries for blog collection will be handled by Eloquenty.
-
If you entered an existing collection to Eloquenty config, there's an import command to import entries to the database:
php artisan eloquenty:import-entries blog
Please delete your collection entries from the filesystem after you verify that entries are imported successfully.
Usage
Eloquenty now should be visible now under Content section of the navigation menu in Control Panel. CRUD for Eloquenty collections works the same way as standard collections.
Antlers
In Antlers templates use the eloquenty tag instead of the collection tag for Eloquenty collections:
{{ eloquenty from="blog" limit="10" taxonomy:tags="demo|example" sort="date:desc" }}
<a href="{{ url }}">{{ title }}</a>
{{ /eloquenty }}
Data retrieval and manipulation
Calling the queryEntries() method of Collection repository, will return the correct QueryBuilder for Eloquenty collections:
\Statamic\Facades\Collection::find('blog')->queryEntries()
Alternatively you can use the Facade Eloquenty::repository() method or EloquentyEntry::query() to retrieve the instance of EntryRepository
(implements Statamic\Contracts\Entries\EntryRepository):
Eloquenty\Facades\Eloquenty::repository()
Eloquenty\Facades\EloquentyEntry::query()
Keep in mind that calling the whereCollection() method will fetch all entries in the table. You should use the query() method instead that returns the query builder instance to build your query.
Changelog
Please see CHANGELOG for more information what has changed recently.
Contributing
Pull requests are welcome and will be fully credited.
- Fork the repo and create your branch from
mainbranch. - Update the README file if needed.
- Make sure your code follows the PSR-2 coding standard.
- Issue that pull request!
License
The MIT License (MIT). Please see License File for more information.
Credits
Many thanks to Statamic for the Eloquent driver and the awesome CMS ❤️
Coffee
If you like this addon please consider buying me a coffee:
nfragkos/eloquenty 适用场景与选型建议
nfragkos/eloquenty 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 9.58k 次下载、GitHub Stars 达 10, 最近一次更新时间为 2021 年 01 月 30 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 nfragkos/eloquenty 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 nfragkos/eloquenty 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 9.58k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 10
- 点击次数: 11
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2021-01-30