spatie/laravel-float-sdk

A Laravel SDK for the Float.com API

0.0.8 2025-04-18 09:40 UTC

README

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

A Laravel-friendly SDK to interact with the Float API (v3).

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-float-sdk

Add the following environment variables to your .env file:

FLOAT_API_TOKEN=your_api_token_here
FLOAT_USER_AGENT=YourAppName (your-email@example.com)

You can publish the config file with:

php artisan vendor:publish --tag="float-sdk-config"

This is the contents of the published config file:

return [
    'api_token' => env('FLOAT_API_TOKEN'),
    'user_agent' => env('FLOAT_USER_AGENT'),
];

Usage

Instantiating the Client

You can use the FloatClient class to interact with the Float API. Why is it called FloatClient and not just Float, you ask? Well, float is a reserved keyword in PHP.

The FloatClient is bound to the Laravel service container and can be injected:

use Spatie\FloatSdk\FloatClient;

public function __construct(protected FloatClient $float) {}

public function index()
{
    $users = $this->float->users()->all();
}

Available endpoints

The FloatClient exposes the following resource groups:

  • users()
  • projects()
  • projectTasks()
  • clients()
  • allocations()

Each group has methods to fetch individual records or lists with optional filters.

Users

Get user by ID

$user = $float->users()->get(1);

Get all users

// Without filters
$users = $float->users()->all();

// With filters
use Spatie\FloatSdk\QueryParameters\GetUsersParams;

$users = $float->users()->all(
    new GetUsersParams(
        active: true,
        departmentId: 5,
    )
);

Projects

Get project by ID

$project = $float->projects()->get(10);

Get all projects

// Without filters
$projects = $float->projects()->all();

// With filters
use Spatie\FloatSdk\QueryParameters\GetProjectsParams;

$projects = $float->projects()->all(
    new GetProjectsParams(
        clientId: 10,
        tagName: 'Design',
        fields: ['id', 'name'],
        expand: ['client'],
    )
);

Project tasks

Get project task by ID

$task = $float->projectTasks()->get(1);

Get all project tasks

// Without filters
$tasks = $float->projectTasks()->all();

// With filters
use Spatie\FloatSdk\QueryParameters\GetProjectTasksParams;

$tasks = $float->projectTasks()->all(
    new GetProjectTasksParams(
        projectId: 42,
        billable: true,
        fields: ['id', 'name'],
    )
);

Clients

Get client by ID

$client = $client->clients()->get(1);

Get all clients

// Without filters
$clients = $float->clients()->all();

// With filters
use Spatie\FloatSdk\QueryParameters\GetClientsParams;

$clients = $float->clients()->all(
    new GetClientsParams(
        fields: ['id', 'name'],
        expand: ['projects'],
    )
);

Allocations

Get allocations by ID

$client = $float->allocations()->get(1);

Get all allocations

// Without filters
$allocations = $float->allocations()->all();

// With filters
use Spatie\FloatSdk\QueryParameters\GetAllocationsParams;

$allocations = $float->allocations()->all(
    new GetAllocationsParams(
        fields: ['id', 'start_date'],
        expand: ['project'],
    )
);

Pagination & Sorting

You can pass a parameter object to the all() methods. All parameters are optional.

  • page (int): Page number (default: 1)
  • perPage (int): Number of items per page (default: 50)
  • sort (string): Sort field (e.g., "name", "modified_since")
use Spatie\FloatSdk\QueryParameters\GetUsersParams;

new GetUsersParams(
    page: 2,
    perPage: 25,
    sort: 'name'
);

Selecting fields

Limit which fields are returned by passing the fields array:

use Spatie\FloatSdk\QueryParameters\GetProjectsParams;

new GetProjectsParams(
    fields: ['id', 'name', 'client_id']
);

Expanding relationships

Some endpoints support expanding related data using the expand array:

use Spatie\FloatSdk\QueryParameters\GetProjectsParams;

new GetProjectsParams(
    expand: ['client']
);

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.