dromedar-design / laravel-prismic
为Prismic自动生成Eloquent模型和更好的模板
v0.2
2022-10-21 07:38 UTC
Requires
- php: ^7.0|^8.0
- prismic/php-sdk: 5.0.1
Requires (Dev)
- orchestra/testbench: ^3.6
- phpunit/phpunit: ^7.0|^8.0
This package is auto-updated.
Last update: 2024-09-21 12:17:05 UTC
README
为Prismic自动生成Eloquent模型和更好的模板
安装
您可以通过composer安装此包
composer require dromedar-design/laravel-prismic
然后您可以在 config/database.php
中将其配置为新数据库连接
'connections' => [ 'prismic' => [ 'driver' => 'prismic', 'database' => 'https://XXX.cdn.prismic.io/api/v2', 'cache' => false, ], // other connections ],
之后,您只需扩展包中提供的模型,您的Prismic API就可以像常规Eloquent模型一样工作了。
<?php namespace App; use DromedarDesign\Prismic\Model; class Post extends Model { // }
关系
关系的工作方式与常规Eloquent模型相同。
访问属性
有三种输出模式
- 原始数据
- 文本
- HTML(这是默认值)
$post = \App\Post::first(); $title = $post->title; // By default it returns the html output // Output: <h1>Hello, this is title</h1>
您可以直接访问其他模式或更改默认值。
$title = $post->title->text; // Output: Hello, this is title $post->setPrismicMode('raw'); $title = $post->title; /** Output: * [ * { * "type": "heading1", * "text": "Hello, this is title", * "spans": [] * } * ] */