glhd/laravel-prismoquent
Composer 安装命令:
composer require glhd/laravel-prismoquent
包简介
Prismoquent lets you access Prismic.io using the same methods you're used to in Eloquent.
关键字:
README 文档
README
This package provides a mostly Eloquent-compatible Model that you can use to access content from Prismic.io as though it were a standard Eloquent model.
App/Page.php
class Page extends \Galahad\Prismoquent\Model { // Automatically inferred from class name ("page") if left unset protected $type; // Cast RichText to text or HTML (all other cast types also supported) protected $casts = [ 'title' => 'text', 'body' => 'html', ]; // Resolve links as though they were relationships public function authorLinkResolver() : ?Person { return $this->hasOne('author', Person::class); } // Also supports repeating groups of links public function similarPagesLinkResolver() { return $this->hasMany('similar_pages.page', static::class); } }
App/Http/Controllers/PageController.php
class PageController extend Controller { public function show(Page $page) { return view('page.show', compact('page')); } }
resources/views/page/show.blade.php
<h1>{{ $page->title }}</h1> <div class="page-body"> {{ $page->body }} </div>
// Familiar API $page = Page::where('document.id', 'W2N5Dx8AAD1TPaYt')->first(); $page = Page::find('W2N5Dx8AAD1TPaYt'); $page = Page::findOrFail('W2N5Dx8AAD1TPaYt'); echo "<h1>{$page->title}</h1>"; echo $page->body; echo "<p>Written by {$page->author->name}</p>" echo "<h2>Similar Pages</h2>"; foreach ($page->similar_pages as $similar_page) { echo "<h3>{$similar_page->title}</h3>"; echo "<p>{$similar_page->meta_description}</p>"; } // With full support for all Prismic predicates Page::where('my.page.body', 'fulltext', 'laravel')->get();
Warning: Active Development
This project is still in active development and may have many bugs. Use at your own risk!
Installation
You can install the package via composer:
composer require glhd/laravel-prismoquent
Usage
See above for a basic example. More details coming soon.
Configuration
Looks for config in your services.php file:
return [ 'prismic' => [ 'endpoint' => env('PRISMIC_ENDPOINT'), // Required 'api_token' => env('PRISMIC_API_TOKEN'), // Optional, depending on your Prismic permissions 'webhook_secret' => env('PRISMIC_WEBHOOK_SECRET'), // Optional, if you're using build-in controller 'register_controller' => false, // Set to false to disable Webhook controller ] ];
Link Resolution
You can register link resolvers as either a callable or a route name:
// In your AppServiceProvider Prismic::registerResolver('page', 'pages.show'); Prismic::registerResolver('person', function(DocumentLink $link) { return url('/people/'.$link->getUid()); }); // In your web.php route file Route::get('/pages/{page}', 'PageController@show')->name('pages.show');
If you do not set up a resolver, Prismoquent will try a resource route
for your document. So Page will try route('pages.show', $uid) or
NewsItem will try route('news_items.show', $uid).
Once your resolvers are defined, you can resolve links in any Prismic Fragment using:
$html = Prismic::asHtml($fragment);
Blade Directives
{{-- Will render slice object using views/slices/slice-type.blade.php --}} @slice($object_implementing_slice_tnterface) {{-- Will render all slices in slice zone using @slice directive --}} @slice($slice_zone_object) {{-- Converts frament to HTML using link resolver --}} @asHtml($fragment) {{-- Converts frament to plain text --}} @asText($fragment) {{-- Converts a DocumentLink fragment to the resolved URL --}} @resolveLink($documentLink)
License
The MIT License (MIT). Please see License File for more information.
glhd/laravel-prismoquent 适用场景与选型建议
glhd/laravel-prismoquent 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 2.28k 次下载、GitHub Stars 达 2, 最近一次更新时间为 2018 年 08 月 03 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「laravel」 「Prismic」 「prismic.io」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 glhd/laravel-prismoquent 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 glhd/laravel-prismoquent 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 glhd/laravel-prismoquent 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
PHP API Client for Prismic.io
Mezzio integration for Prismic. Let’s call it ”Primo“…
CLI tooling for developing Prismic content models
A Laravel package for using Prismic.io
Add Symfony wrapper for prismic package
Alfabank REST API integration
统计信息
- 总下载量: 2.28k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 2
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2018-08-03