Skip to content

spatie/laravel-harvest-sdk

Repository files navigation

A Laravel SDK for the Harvest.com API

Latest Version on Packagist GitHub Tests Action Status GitHub Code Style Action Status Total Downloads

A Laravel-friendly SDK to interact with the Harvest API

Support us

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.

Installation

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])'

Usage

To start interacting with the Harvest API, you can resolve the Harvest instance from the container:

use Spatie\Harvest\Harvest;

$harvest = app(Harvest::class);

Users

Retrieve the authenticated user

use Spatie\Harvest\Harvest;
use Spatie\Harvest\Resources\UserResource;

public function user(Harvest $harvest): UserResource
{
    return $harvest->users()->me();
}

Retrieve all users

use Spatie\Harvest\Harvest;
use Spatie\Harvest\Resources\UserResource;

/** @return array<UserResource> */
public function user(Harvest $harvest): array
{
    return $harvest->users()->all();
}

Projects

Retrieve all projects

use Spatie\Harvest\Harvest;
use Spatie\Harvest\Resources\ProjectResource;

/** @return array<ProjectResource> */
public function user(Harvest $harvest): array
{
    return $harvest->projects()->all();
}

Filtering

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);
}

Testing

composer test

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security Vulnerabilities

Please review our security policy on how to report security vulnerabilities.

Credits

License

The MIT License (MIT). Please see License File for more information.

About

A Laravel-friendly SDK to interact with the Harvest API

Resources

License

Contributing

Stars

Watchers

Forks

Releases

No releases published

Sponsor this project

 

Packages

No packages published

Contributors 5

Languages