stefblokdijk / laravel-prismic-helper
Prismic Helper for Laravel
dev-master
2021-03-17 01:41 UTC
Requires
- php: ^7.1|^8.0
- illuminate/support: ^5.5|^6|^7|^8
- prismic/php-sdk: 5.*
Requires (Dev)
- orchestra/testbench: 3.8.*
- phpunit/phpunit: ^7.0
This package is auto-updated.
Last update: 2024-10-17 09:21:04 UTC
README
Work In Progress package to easily use the main functionalities of Prismic in your Laravel Project
Installation
You can install the package via composer:
composer require stefblokdijk/laravel-prismic-helper
Add the following to your .env
file
PRISMIC_REPOSITORY_URL=https://example.cdn.prismic.io/api/v2
If you are using a multilanguage repository, you can also set the default language in your .env
PRISMIC_LANGUAGE=nl
Examples
Get Content from a single type
use LaravelPrismicHelper; LaravelPrismicHelper::getSingle($type);
Get Content from UID
LaravelPrismicHelper::getByUID($uid, $type);
Get all items by an given type. This will return an collection
LaravelPrismicHelper::getByType($type);
You can also filter using the getByType
function:
// 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'), ]);
Query by Language
LaravelPrismicHelper::language('nl')->getSingle(type);
Helper functions for Blade templating
You have the following functions available to you:
Examples:
<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>
Working with content groups
@foreach(prismic_group($content, 'products') as $product) <li>{{ prismic_as_text($product, 'name') }}</li> @endforeach
Changelog
Please see CHANGELOG for more information what has changed recently.
Security
If you discover any security related issues, please email hello@stefblokdijk.com instead of using the issue tracker.
License
The MIT License (MIT). Please see License File for more information.