|
1 | | -# directus-api-laravel |
2 | | - API Wrapper for Laravel 5 |
| 1 | +# Directus API Wrapper for Laravel 5 |
| 2 | + |
| 3 | + |
| 4 | + |
| 5 | + |
| 6 | + |
| 7 | +This package allows users to easily consume the REST API provided by the Directus Headless CMS system in any Laravel app. |
| 8 | + |
| 9 | +If your looking for an API Wrapper without using Laravel, see [c14r/directus-api](https://github.com/C14r/directus-api). |
| 10 | + |
| 11 | +# Installing |
| 12 | + |
| 13 | +The recommended way to install Directus-API is through |
| 14 | +[Composer](https://getcomposer.org/). |
| 15 | + |
| 16 | +```bash |
| 17 | +composer require c14r/directus-api-laravel |
| 18 | +``` |
| 19 | + |
| 20 | +In Laravel 5, update the `config/app.php` providers array with the Service Provider: |
| 21 | + |
| 22 | +```php |
| 23 | +C14r\Directus\Laravel\DirectusServiceProvider::class, |
| 24 | +``` |
| 25 | + |
| 26 | +# Configuration |
| 27 | + |
| 28 | +By default, the package is set up to use the following configuration values from your `.env` file: |
| 29 | + |
| 30 | ++ `DIRECTUS_URL` - The base URL of your Directus instance. |
| 31 | ++ `DIRECTUS_PROJECT` - The Directus project, you want to use |
| 32 | + |
| 33 | +## Authentification |
| 34 | + |
| 35 | +You can enter |
| 36 | ++ `DIRECTUS_API_KEY` - The key generated by Directus and associated with a user |
| 37 | + |
| 38 | +or |
| 39 | + |
| 40 | ++ `DIRECTUS_USERNAME` - The Directus username |
| 41 | ++ `DIRECTUS_PASSWORD` - The password for you Directus user |
| 42 | + |
| 43 | +If you enter non of them, the guest access is used. |
| 44 | + |
| 45 | +## Laravel |
| 46 | + |
| 47 | +If you would like to use a config file, you can publish the default config by running the following command: |
| 48 | + |
| 49 | +```bash |
| 50 | +php artisan vendor:publish --provider="C14r\Directus\Laravel\DirectusServiceProvider" |
| 51 | +``` |
| 52 | + |
| 53 | +This will publish a config file to `config/directus.php`. |
| 54 | + |
| 55 | +# Usage |
| 56 | + |
| 57 | +To utilize the API Wrapper, use dependency injection to resolve: |
| 58 | + |
| 59 | +```php |
| 60 | +public function __construct(Directus $directus) |
| 61 | +{ |
| 62 | + $this->api = $directus; |
| 63 | +} |
| 64 | +``` |
| 65 | + |
| 66 | +or use the helper function: |
| 67 | + |
| 68 | +```php |
| 69 | +directus() // or directus('connection') |
| 70 | +``` |
| 71 | +## How the API works |
| 72 | + |
| 73 | +Take a look at [c14r/directus-api](https://github.com/C14r/directus-api) for more details. |
0 commit comments