stefblokdijk/laravel-prismic-helper

dev-master 2021-03-17 01:41 UTC

This package is auto-updated.

Last update: 2024-09-17 09:10:16 UTC


README

Latest Version on Packagist Total Downloads

工作在进度中的包,用于在Laravel项目中轻松使用Prismic的主要功能

安装

您可以通过composer安装此包

composer require stefblokdijk/laravel-prismic-helper

将以下内容添加到您的 .env 文件中

PRISMIC_REPOSITORY_URL=https://example.cdn.prismic.io/api/v2

如果您正在使用多语言存储库,您也可以在 .env 中设置默认语言

PRISMIC_LANGUAGE=nl

示例

获取单个类型的内蓉

use LaravelPrismicHelper;

LaravelPrismicHelper::getSingle($type);

通过UID获取内容

LaravelPrismicHelper::getByUID($uid, $type);

通过给定类型获取所有项目。这将返回一个集合

LaravelPrismicHelper::getByType($type);

您还可以使用 getByType 函数进行过滤

// use options as second argument. Example: sort by by field (https://prismic.io/docs/php/query-the-api/order-your-result)
LaravelPrismicHelper::getByType($type, [
    'orderings' => '[my.news.date desc]'
]);

// Use multiple predicates as third arguments. Example: fullText search for the category (https://prismic.io/docs/php/query-the-api/fulltext-search)
use Prismic\Predicates;

LaravelPrismicHelper::getByType($type, [], [
    Predicates::fulltext('my.product.category', 'Some Category'),
]);

按语言查询

LaravelPrismicHelper::language('nl')->getSingle(type);

Blade模板的辅助函数

您有以下函数可用

示例

<h1>{{ prismic_as_text($content, 'subtitle') }}<h1>

<img src="{{ prismic_image_url($content, 'image') }}" alt="{{ prismic_image_alt($content, 'image') }}" />

<span>{{ prismic_as_date($content, 'created_at', 'LL') }}</span>

处理内容组

@foreach(prismic_group($content, 'products') as $product)
    <li>{{ prismic_as_text($product, 'name') }}</li>
@endforeach

变更日志

有关最近更改的更多信息,请参阅变更日志

安全性

如果您发现任何与安全相关的问题,请通过hello@stefblokdijk.com 发送电子邮件,而不是使用问题跟踪器。

许可证

MIT许可证(MIT)。有关更多信息,请参阅许可证文件