Add the following to your composer.json
{
"require": {
"hirvi/ticketco-php": "~1.0"
}
}
We've added some classes to help Laravel 5 users make use of the library with ease.
You can register our service provider in your app.php
config file.
// config/app.php
'providers' => [
...
TicketCo\Laravel\TicketCoServiceProvider::class
]
If you prefer facades, make sure you add this as well:
// config/app.php
'aliases' => [
...
'TicketCo' => TicketCo\Laravel\TicketCoFacade::class
]
There are only one configuration option you need to fill in. Publish the config by running:
php artisan vendor:publish
Now, the config file will be located under config/ticketco.php
:
<?php
return [
/*
|--------------------------------------------------------------------------
| TicketCo API key
|--------------------------------------------------------------------------
|
| To obtain an API key, contact TicketCo or fill out this form:
| https://app.pipefy.com/public_form/155824
|
*/
'apikey' => ''
];
Unless you are using the Laravel Facade, you need to initialize the client by passing it the API-key.
<?php
require_once __DIR__ . '/vendor/autoload.php';
$ticketco = new TicketCo\Client('api-key');
<?php
// Fetch all events
$events = $ticketco->events()->all();
// ... or if you are using the Laravel Facade
$events = TicketCo::events()->all();
// Using the Collection object, you can
// loop through all events using `each(callback)`
$events->each(function($event) {
echo $event->title;
});
// ... or you can use foreach like with any other object/array
foreach($events as $event) {
echo $event->title;
}
// ... or if you don't like the Collection object
// you can transform it into an array
$events = $events->toArray();
// Fetch single event
$event = $ticketco->events()->get('<id>');
echo $event->title;
Check whether the event is available or has ended.
$status = $ticketco->events()->status('<id>'); // Will return "available" or "ended".
Queries will return an instance of the Illuminate\Support\Collection object, which is really easy to work with. If you don't want to use the Collection object however, you can transform it into an array using $result->toArray()
.
TicketCo's API documentation is located here; http://apidoc.ticketco.no/api/v1/public.