https://github.com/theplanworks/directus-laravel
A Laravel 5 Wrapper for the Directus REST API
https://github.com/theplanworks/directus-laravel
directus laravel php
Last synced: 5 months ago
JSON representation
A Laravel 5 Wrapper for the Directus REST API
- Host: GitHub
- URL: https://github.com/theplanworks/directus-laravel
- Owner: theplanworks
- License: mit
- Created: 2017-02-16T01:38:28.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2017-03-02T02:23:11.000Z (over 9 years ago)
- Last Synced: 2025-10-30T08:51:52.943Z (8 months ago)
- Topics: directus, laravel, php
- Language: PHP
- Size: 20.5 KB
- Stars: 6
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
- License: LICENSE
Awesome Lists containing this project
README
# Directus API Wrapper for Laravel 5
This package allows users to easily consume the REST API provided by the [Directus](https://getdirectus.com) Headless CMS system in any Laravel app.
## Installation
Install via [composer](https://getcomposer.org) using the command line:
```bash
composer require theplanworks/directus-laravel
```
In Laravel 5, update the `config/app.php` providers array with the Service Provider:
```php
thePLAN\DirectusLaravel\DirectusLaravelServiceProvider::class,
```
### Configuration
By default, the package is set up to use the following configuration values read from your `.env` file:
+ `DIRECTUS_CMS_URL` - The base URL of your CMS instance.
+ `DIRECTUS_API_KEY` - The key generated by the CMS and associated with a valid user that authenticates requests
If you would like to use a config file, you can publish the default config by running the following command:
```bash
php artisan vendor:publish --provider="thePLAN\DirectusLaravel\DirectusLaravelServiceProvider"
```
This will publish a config file to `config/directus-laravel.php`.
## Usage
To utilize the API Wrapper, use dependency injection to resolve:
```php
public function __construct(DirectusLaravel $directusAPI)
{
$this->api = $directusAPI;
}
```
Then you can make the following calls:
### getTableRows
```php
$value = $this->api->getTableRows($table);
```
Where `$table` is the name of the Directus table you would like to access.
### getTableRow
```php
$value = $this->api->getTableRow($table, $id);
```
Where `$table` is the name of the Directus table you would like to access, and `$id` is the unique ID of the record being requested.
### getTableRowBySlug
```php
$value = $this->api->getTableRowBySlug($table, $slug)
```
Where `$table` is the name of the Directus table you would like to access, and `$slug` is the unique slug property of the record being requested. PREREQUISITE: A `slug` field must have been created on the table.
### getFile
```php
$this->api->getFile($url);
```
Where `$url` is the file url you would like to return, such as `/storage/uploads/00000000001.png`.
## License
This package is open-sourced software licensed under the [MIT license](http://opensource.org/licenses/MIT).