Skip to Content
LaravelLaravel REST SDK

Laravel Rest Provider for Prepr CMS

This Laravel package is a provider for the Prepr REST API.

Basics

  • The SDK on GitHub 
  • Supported: Laravel v12x and v13x (SDK ^5.0).
  • Requires PHP ^8.2 and GuzzleHttp ^7.3 or ^8.0.

Older SDK releases for Laravel 8 to 11 are no longer supported (no bug fixes or security updates). Upgrade to Laravel 12 or 13 and SDK ^5.0 when you can.

Installation

You can install the Provider as a composer package.

composer require preprio/laravel-rest-sdk:"^5.0"

Publish config

Publish prepr.php config.

prepr.php
php artisan vendor:publish --provider="Preprio\PreprServiceProvider"

Set up your .env file configuration

You can set the default configuration in your .env file of you Laravel project.

.env
PREPR_URL=https://cdn.prepr.io/ PREPR_TOKEN=<YOUR-ACCESS-TOKEN>

Laravel local caching

To make use of the caching feature of Laravel, add the following parameters to your .env file.

.env
PREPR_CACHE=true PREPR_CACHE_TIME=1800

Making your first request

Let’s start with getting all content items from your Prepr environment.

<?php use Preprio\Prepr; $apiRequest = new Prepr; $apiRequest ->path('publications') ->query([ 'fields' => 'items' ]) ->get(); if($apiRequest->getStatusCode() == 200) { print_r($apiRequest->getResponse()); }

To get a single content item, pass the ID to the request.

<?php use Preprio\Prepr; $apiRequest = new Prepr; $apiRequest ->path('publications/{id}', [ 'id' => '1236f0b1-b26d-4dde-b835-9e4e441a6d09' ]) ->query([ 'fields' => 'items' ]) ->get(); if($apiRequest->getStatusCode() == 200) { print_r($apiRequest->getResponse()); }

Override the AccessToken in a request

The authorization can also be set for one specific request ->url('url')->authorization('token').

Autopaging

$apiRequest = (new Prepr) ->path('publications') ->query([ 'limit' => 200 // optional ]) ->autoPaging(); if($apiRequest->getStatusCode() == 200) { dump($apiRequest->getResponse()); }

Create, Update & Destroy

Post

$apiRequest = (new Prepr) ->path('publications') ->params([ 'body' => 'Example' ]) ->post(); if($apiRequest->getStatusCode() == 201) { dump($apiRequest->getResponse()); }

Put (Update)

$apiRequest = (new Prepr) ->path('publications') ->params([ 'body' => 'Example' ]) ->put(); if($apiRequest->getStatusCode() == 200) { dump($apiRequest->getResponse()); }

Delete

$apiRequest = (new Prepr) ->path('publications/{id}',[ 'id' => 1 ]) ->delete(); if($apiRequest->getStatusCode() == 204) { // Deleted. }

Multipart/Chunk upload

  • Option 1
use Illuminate\Support\Facades\Storage; $source = Storage::readStream('image.jpg'); $apiRequest = (new Prepr) ->path('assets') ->params([ 'body' => 'Example', ]) ->file($source); if($apiRequest->getStatusCode() == 200) { dump($apiRequest->getResponse()); }
  • Option 2
use Illuminate\Support\Facades\Storage; $source = Storage::get('image.jpg'); $apiRequest = (new Prepr) ->path('assets') ->params([ 'body' => 'Example', ]) ->file($source, 'image.jpg'); if($apiRequest->getStatusCode() == 200) { dump($apiRequest->getResponse()); }

Debug

For debug you can use getRawResponse()

Last updated on