A Laravel-friendly SDK to interact with the Harvest API
We invest a lot of resources into creating best in class open source packages. You can support us by buying one of our paid products.
We highly appreciate you sending us a postcard from your hometown, mentioning which of our package(s) you are using. You'll find our address on our contact page. We publish all received postcards on our virtual postcard wall.
You can install the package via composer:
composer require spatie/laravel-harvest-sdk
You can publish the config file with:
php artisan vendor:publish --tag="laravel-harvest-sdk-config"
Add your Harvest credentials to your .env file:
HARVEST_ACCOUNT_ID=your-account-id
HARVEST_ACCESS_TOKEN=your-access-token
HARVEST_USER_AGENT='name ([email protected])'
To start interacting with the Harvest API, you can resolve the Harvest instance from the container:
use Spatie\Harvest\Harvest;
$harvest = app(Harvest::class);
use Spatie\Harvest\Harvest;
use Spatie\Harvest\Resources\UserResource;
public function user(Harvest $harvest): UserResource
{
return $harvest->users()->me();
}
use Spatie\Harvest\Harvest;
use Spatie\Harvest\Resources\UserResource;
/** @return array<UserResource> */
public function user(Harvest $harvest): array
{
return $harvest->users()->all();
}
use Spatie\Harvest\Harvest;
use Spatie\Harvest\Resources\ProjectResource;
/** @return array<ProjectResource> */
public function user(Harvest $harvest): array
{
return $harvest->projects()->all();
}
You can filter the results by passing an array of filters to the all
method:
use Spatie\Harvest\Harvest;
use Spatie\Harvest\Resources\UserResource;
/** @return array<UserResource> */
public function user(Harvest $harvest): array
{
return $harvest->users()->all(active: true);
}
composer test
Please see CHANGELOG for more information on what has changed recently.
Please see CONTRIBUTING for details.
Please review our security policy on how to report security vulnerabilities.
The MIT License (MIT). Please see License File for more information.