The Cierra Connect Laravel SDK provides an easy way to integrate with the Cierra Connect API in your Laravel applications.
Follow these steps to install and set up the package:
-
Install the package using Composer:
composer require cierrateam/connect-laravel-sdk
-
Add the service provider to your
config/app.php
file in theproviders
array:'providers' => [ // ... \Cierra\Connect\ConnectServiceProvider::class, ],
-
Publish the configuration file (optional):
php artisan vendor:publish --tag=cierra-connect-config
-
Add your Cierra Connect API key to your
.env
file:CIERRA_CONNECT_KEY=your_api_key_here
Replace 'your_api_key_here' with your actual Cierra Connect API key.
Here's an example of how you can use the Cierra Connect Laravel SDK in your controllers:
<?php
namespace App\Http\Controllers;
use Cierra\Connect\ConnectManager;
use Illuminate\Http\Request;
class TestCierraConnectController extends Controller
{
public function test(Request $request, ConnectManager $connectManager)
{
$CONNECTION = 'my_api_connection_key';
$apiClient = $connectManager->getInstance($CONNECTION);
// Get a list of entities
$items = $apiClient->entity('cars')->list();
dump($items); // Laravel collection returned
dump($items->first());
// Pagination
$items = $apiClient->entity('cars')->list(4, 100);
dump($items);
// Get specific item by ID
$item = $apiClient->entity('cars')->get(314591);
dump($item);
// Get additional API response data
$item = $apiClient->entity('cars')->asRawResponse()->get(314588);
dump($item);
}
}