Work In Progress package to easily use the main functionalities of Prismic in your Laravel Project
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
use LaravelPrismicHelper;
LaravelPrismicHelper::getSingle($type);
LaravelPrismicHelper::getByUID($uid, $type);
LaravelPrismicHelper::getByType($type);
// 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);
You have the following functions available to you:
Function | Returns |
---|---|
prismic_as_text($content, $key) |
Plain text content |
prismic_as_html($content, $key) |
Html content |
prismic_as_date($content, $key, $format) |
ISO date format using Carbon::isoFormat($format) |
prismic_file_url($content, $key) |
File Url |
prismic_image_url($content, $key) |
Image Url |
prismic_image_alt($content, $key) |
Image Alt Text |
prismic_group($content, $key) |
Collection of items |
<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
Please see CHANGELOG for more information what has changed recently.
If you discover any security related issues, please email [email protected] instead of using the issue tracker.
The MIT License (MIT). Please see License File for more information.