Laravel 10.x Directus API Wrapper
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:
DIRECTUS_API_KEY
- The key generated by Directus associated with a user.
or
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.