PHPackages                             lionelhenne/laravel-cockpit-cms - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [API Development](/categories/api)
4. /
5. lionelhenne/laravel-cockpit-cms

ActiveLibrary[API Development](/categories/api)

lionelhenne/laravel-cockpit-cms
===============================

A lightweight client for the Cockpit CMS GraphQL API.

v1.5.8(6mo ago)053MITPHPPHP ^8.2

Since Sep 10Pushed 5mo agoCompare

[ Source](https://github.com/lionelhenne/laravel-cockpit-cms)[ Packagist](https://packagist.org/packages/lionelhenne/laravel-cockpit-cms)[ RSS](/packages/lionelhenne-laravel-cockpit-cms/feed)WikiDiscussions main Synced today

READMEChangelogDependencies (2)Versions (21)Used By (0)

Laravel Client for Cockpit CMS (GraphQL)
========================================

[](#laravel-client-for-cockpit-cms-graphql)

[![Latest Version on Packagist](https://camo.githubusercontent.com/2efb7ecb8ef2cde33c2f3034f4fc2e0b24a7d20e46f18114f5bc52cad2f8b276/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6c696f6e656c68656e6e652f6c61726176656c2d636f636b7069742d636d732e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/lionelhenne/laravel-cockpit-cms)[![License: MIT](https://camo.githubusercontent.com/1b01ef0024ba0866c115986b895301f657c1b21fc29f05c4844b7f2e8d89204d/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c6963656e73652d4d49542d79656c6c6f772e7376673f7374796c653d666c61742d737175617265)](https://opensource.org/licenses/MIT)

A simple and lightweight client to query the [Cockpit CMS](https://getcockpit.com/) GraphQL API from a Laravel application.

Installation
------------

[](#installation)

You can install this package via Composer.

```
composer require lionelhenne/laravel-cockpit-cms
```

The Service Provider will be automatically registered thanks to Laravel's package discovery.

Configuration
-------------

[](#configuration)

1. **Publish the configuration file**

    To set your API credentials, you first need to publish the package's configuration file. It will be copied to `config/cockpit.php`.

    ```
    php artisan vendor:publish --tag="cockpit-config"
    ```
2. **Add your environment variables**

Next, open your `.env` file and add the following keys with your information:

```
COCKPIT_URL="[https://your-cockpit-site.com](https://your-cockpit-site.com)"
COCKPIT_GRAPHQL_ENDPOINT="[https://your-cockpit-site.com/api/gql](https://your-cockpit-site.com/api/gql)"
COCKPIT_API_TOKEN="API-xxxxxxxxxxxxxxxxxxxx"
```

> **Note regarding Public APIs:** If your Cockpit API access is configured as **Public** (no token required), you can leave `COCKPIT_API_TOKEN` empty in your `.env` file. The client will automatically skip the `Authorization` header to avoid 401 errors.

Usage
-----

[](#usage)

This package is designed to simplify fetching data by allowing you to batch multiple GraphQL query fragments into a single API call, with caching built-in.

### High-Level Helpers (Recommended)

[](#high-level-helpers-recommended)

The recommended way to interact with Cockpit is via the high-level `execute()` and `executeCached()` methods. These methods automatically assemble your query fragments.

- `Cockpit::execute(array $queries)`: Assembles and executes a batch of query fragments without caching.
- `Cockpit::executeCached(array $queries, string $cacheKey, $duration = null)`: Assembles, executes, and caches the result. The duration defaults to 1 month.

### Recommended Usage (Facade Example)

[](#recommended-usage-facade-example)

This example shows how to fetch all data for a homepage in a single, cached API call.

```
