承接 webhappens/prismic 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

webhappens/prismic

Composer 安装命令:

composer require webhappens/prismic

包简介

A Laravel package for using Prismic.io

README 文档

README

tests

A Laravel wrapper for Prismic.io

This package makes it super quick and easy to work with Prismic.io in Laravel.

  • Object-oriented design
  • Eloquent-style query interface
  • Auto-magically render Slices and Fields as HTML
  • Automatic link resolution
  • Nested Document support
  • Out-the-box caching and preview sessions
  • Super-charged web hooks (Coming soon)

Documents

Each Custom Type within Prismic should have a corresponding Document model in your project. Document models make it easy for you to query your Prismic repository and organise your code around your content models.

Defining Document Models

To get started, let's create a Document model. All Document models extend the WebHappens\Prismic\Document class.

The most basic and fundamental property of a Document model is its type property. This property indicates which Prismic Custom Type the Document model corresponds to:

<?php

namespace App;

use WebHappens\Prismic\Document;

class Article extends Document
{
    /**
     * The 'API ID' of the Custom Type associated with the document model.
     *
     * @var string
     */
    protected static $type = 'article';
}

Registering Document Models

Before Document models are available they must be registered in a Service Provider using the Prismic::documents() method. Typically this would happen in the register method of your App\Providers\AppServiceProvider class.

use App\Article;
use WebHappens\Prismic\Prismic;

public function register()
{
    Prismic::documents([
        Article::class,
    ]);
}

Retrieving Documets

Once you have created a Document model and its associated content in Prismic, you are ready to start retrieving data from your repository.

All Documents

You may retrieve all Documents for a specific type using the all method. They will be returned inside a Laravel Collection object:

// Retrieve all Article Documents
$articles = Article::all();

Chunking Results

If you need to process a lot of Documents, use the chunk command. The chunk method will retrieve a "chunk" of Document models, feeding them to a given Closure for processing. This will conserve memory when working with large result sets:

// Process each Article in chunks of 100
Article::chunk(100, function ($articles) {
    foreach ($articles as $article) {
        //
    }
});

Please note that the largest chunk size is 100 due to a limit on the Prismic API.

Single Documents

In addition to retrieving all Documents for a given type, you may also retrieve single records by passing the Document ID into the find method. Instead of returning a Laravel Collection, this method returns a single Document instance:

// Retrive the Article with an ID of WAjgAygABN3B0a-a
$article = Article::find('WAjgAygABN3B0a-a');

Single Type Documents

If you have created a Single Type Document, a Homepage, for example, you may use the single method to retrieve the Document model instance, without having to pass a Document ID:

// Retrieve a Single Type Document
$homepage = Homepage::single();

webhappens/prismic 适用场景与选型建议

webhappens/prismic 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1.43k 次下载、GitHub Stars 达 5, 最近一次更新时间为 2020 年 03 月 18 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「Prismic」 「webhappens」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 webhappens/prismic 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 webhappens/prismic 我们能提供哪些服务?
定制开发 / 二次开发

基于 webhappens/prismic 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 1.43k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 5
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 5
  • Watchers: 2
  • Forks: 2
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2020-03-18