nikba/directus-api-laravel

Directus v8.8.1 API Wrapper for Laravel 10.x

v1.1 2023-10-15 05:37 UTC

This package is auto-updated.

Last update: 2024-09-15 07:36:30 UTC


README

Packagist Version Directus Version Laravel Version

This package simplifies the consumption of the Directus Headless CMS REST API within Laravel applications.

If you're seeking an API Wrapper for Directus without using Laravel, please refer to nikba/directus-api.

Installation

The recommended method for installing Directus-API is via Composer.

composer require nikba/directus-api-laravel

In Laravel, update the config/app.php providers array with the Service Provider:

Nikba\Directus\Laravel\DirectusServiceProvider::class,

Configuration

By default, the package is configured to use the following values from your .env file:

  • DIRECTUS_URL - The base URL of your Directus instance.
  • DIRECTUS_PROJECT - The Directus project you wish to use.

Authentication

You can provide authentication through:

  1. DIRECTUS_API_KEY - The key generated by Directus associated with a user.

or

  1. DIRECTUS_USERNAME - The Directus username. DIRECTUS_PASSWORD - The password for your Directus user.

If none of these authentication options are provided, guest access will be used.

Laravel Configuration File

If you prefer using a configuration file, you can publish the default config by running this command:

php artisan vendor:publish --provider="Nikba\Directus\Laravel\DirectusServiceProvider"

This will create a config file at config/directus.php.

Usage

To use the API Wrapper, you can either use dependency injection to resolve it:

public function __construct(Directus $directus)
{
    $this->api = $directus;
}

Or use the helper function:

directus() // or directus('connection')

Understanding the API

For a more in-depth understanding of how the API works, please refer to nikba/directus-api.