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.
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'),
];
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();
}
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.
$user = $float->users()->get(1);
// Without filters
$users = $float->users()->all();
// With filters
use Spatie\FloatSdk\QueryParameters\GetUsersParams;
$users = $float->users()->all(
new GetUsersParams(
active: true,
departmentId: 5,
)
);
$project = $float->projects()->get(10);
// 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'],
)
);
$task = $float->projectTasks()->get(1);
// 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'],
)
);
$client = $client->clients()->get(1);
// Without filters
$clients = $float->clients()->all();
// With filters
use Spatie\FloatSdk\QueryParameters\GetClientsParams;
$clients = $float->clients()->all(
new GetClientsParams(
fields: ['id', 'name'],
expand: ['projects'],
)
);
$client = $float->allocations()->get(1);
// 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'],
)
);
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'
);
Limit which fields are returned by passing the fields
array:
use Spatie\FloatSdk\QueryParameters\GetProjectsParams;
new GetProjectsParams(
fields: ['id', 'name', 'client_id']
);
Some endpoints support expanding related data using the expand
array:
use Spatie\FloatSdk\QueryParameters\GetProjectsParams;
new GetProjectsParams(
expand: ['client']
);
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.