Laravel SDK

The FoPost PHP client wired into Laravel, with a service provider, a facade, and config.

fopost/laravel is a thin wrapper over fopost/sdk: it binds the client into the container, adds a Fopost facade, and gives you a publishable config file. Every platform connection, token refresh, and delivery still happens on the hosted API, so there is nothing to run yourself.

Needs PHP 8.1 or newer and Laravel 10, 11, or 12.

composer require fopost/laravel

This is a 0.x release. The surface is still settling and a minor version may break something. Pin an exact version if that matters to you.

Published on Packagist. Source and issues: github.com/fopost/fopost-laravel. MIT licensed.

Configuration

The service provider and the Fopost facade alias are auto-discovered, so the only required step is the key:

FOPOST_API_KEY=fp_your_key_here

Everything else is optional:

VariableDefaultWhat it does
FOPOST_API_KEYnone, requiredYour API key
FOPOST_API_URLhttps://api.fopost.comAPI base URL
FOPOST_API_TIMEOUT30Seconds to wait for one request
FOPOST_API_MAX_RETRIES3Attempts for a rate limited request

Publish the config file if you want to edit it directly:

php artisan vendor:publish --tag=fopost-config

Quick start

use Fopost\Laravel\Facades\Fopost;

$workspace = Fopost::workspaces()->list()[0];
$accounts = Fopost::accounts()->list($workspace->id);

$post = Fopost::posts()->create(
    workspaceId: $workspace->id,
    content: 'Shipping today: scheduled posting straight from Laravel.',
    accounts: $accounts,
    status: 'scheduled',
    scheduleAt: now()->addHour(),
);

Prefer injection over the facade? Type hint the client and the container hands you the configured singleton:

use Fopost\Sdk\Client;

public function __invoke(Client $fopost)
{
    return $fopost->posts()->list(status: 'scheduled');
}

Resources

The facade exposes the same surface as the PHP client, so What is on the client is the full list.

$page = Fopost::posts()->list(workspaceId: $workspaceId, status: 'scheduled');
Fopost::posts()->schedule($postId, now()->addDay());
Fopost::posts()->publish($postId);

foreach (Fopost::posts()->iterate(workspaceId: $workspaceId) as $post) {
    // walks page by page for you
}

$accounts = Fopost::accounts()->list($workspaceId);
Fopost::accounts()->disconnect($accountId);

$workspaces = Fopost::workspaces()->list();

Errors

Exceptions come from the underlying client, so the table on the PHP SDK page applies unchanged. Catch Fopost\Sdk\Exception\FopostException to handle them all.

Not the self-hosted package

This publishes through your FoPost account. The separate self-hosted library, which talks to each network from your own server with your own app credentials, is documented in its own repository and is not part of the Cloud docs.

Next

Related documentation
  • SDKs & Integrations

    Official FoPost clients for TypeScript, Python, PHP, Ruby, Go, Rust, Java, .NET, Swift, Kotlin, Dart, and Elixir, framework integrations from Laravel to Next.js, and tooling for the CLI, CI, Terraform, and the automation platforms.

  • SDKs Overview

    Every official FoPost client, what it covers, and how to pick one.

  • TypeScript SDK

    The official TypeScript and Node.js client for the FoPost API.

  • Python SDK

    The official Python client for the FoPost API.

  • PHP SDK

    The official PHP client for the FoPost API, with no framework and no HTTP library.

  • Ruby SDK

    The official Ruby client for the FoPost API, with no runtime dependencies.

  • Go SDK

    The official Go client for the FoPost API.

  • Rust SDK

    The official Rust client for the FoPost API, async and built on reqwest.

Was this helpful?

On this page