FastComments.com

Add Comments to Your Laravel App

This is the official Laravel Package for FastComments.

A Laravel package that wraps the FastComments PHP SDK and SSO library, providing Blade components, SSO integration, and full API access.

Repository

View on GitHub

AI coding agents Internal Link

skills.sh

Give your coding agent the FastComments context it needs - widgets, configuration, Secure SSO, the REST API, and the SDKs:

npx skills add fastcomments/skills

Works with Claude Code, Codex, Cursor, Copilot, Gemini, and every other agent the skills CLI supports.

Requirements Internal Link

  • PHP 8.1+
  • Laravel 10, 11, or 12

Installation Internal Link

composer require fastcomments/laravel

Publish the configuration file:

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

Add your credentials to .env:

FASTCOMMENTS_TENANT_ID=your-tenant-id
FASTCOMMENTS_API_KEY=your-api-key

For EU region:

FASTCOMMENTS_REGION=eu

Blade Components Internal Link

Comment Widget

<x-fastcomments />

\{{-- With options --}}
<x-fastcomments
    url-id="my-page-id"
    url="https://example.com/my-page"
    locale="en_us"
    :has-dark-background="true"
    default-sort-direction="MR"
/>

Live Chat

<x-fastcomments-live-chat url-id="chat-room-1" />

Comment Count

<x-fastcomments-comment-count url-id="my-page-id" />
<x-fastcomments-comment-count url-id="my-page-id" :number-only="true" />

SSO Internal Link

Enable SSO in your .env:

FASTCOMMENTS_API_KEY=your-api-key
FASTCOMMENTS_SSO_ENABLED=true
FASTCOMMENTS_SSO_MODE=secure

The API key is required for secure SSO — it is used to sign the SSO payload.

Config-Based Mapping

In config/fastcomments.php, map FastComments fields to your User model attributes:

'sso' => [
    'enabled' => true,
    'mode' => 'secure',
    'user_map' => [
        'id' => 'id',
        'email' => 'email',
        'username' => 'name',
        'avatar' => 'profile.avatar_url', // dot notation supported
    ],
    'is_admin' => fn ($user) => $user->hasRole('admin'),
    'is_moderator' => fn ($user) => $user->hasRole('moderator'),
],

Interface-Based Mapping

For more control, implement the MapsToFastCommentsUser interface on your User model:

use FastComments\Laravel\SSO\Contracts\MapsToFastCommentsUser;

class User extends Authenticatable implements MapsToFastCommentsUser
{
    public function toFastCommentsUserData(): array
    {
        return [
            'id' => (string) $this->id,
            'email' => $this->email,
            'username' => $this->display_name,
            'avatar' => $this->avatar_url,
            'is_admin' => $this->hasRole('admin'),
        ];
    }
}

When the interface is implemented, it takes precedence over config-based mapping.

SSO in Blade

When SSO is enabled, the <x-fastcomments /> component automatically injects SSO data for the authenticated user.

API Access Internal Link

Via Facade

use FastComments\Laravel\Facades\FastComments;

// Admin API (requires API key)
$comments = FastComments::admin()->getComments('tenant-id');

// Public API
$comments = FastComments::publicApi()->getCommentsPublic('tenant-id', 'url-id');

// SSO
$ssoPayload = FastComments::sso()->forWidget();
$token = FastComments::sso()->tokenFor($user);

Via Dependency Injection

use FastComments\Laravel\FastCommentsManager;

class CommentController extends Controller
{
    public function index(FastCommentsManager $fc)
    {
        $comments = $fc->admin()->getComments($fc->tenantId());
        // ...
    }
}

Direct SDK Access

use FastComments\Client\Api\DefaultApi;

class CommentController extends Controller
{
    public function index(DefaultApi $api)
    {
        $comments = $api->getComments('tenant-id');
        // ...
    }
}

Configuration Reference Internal Link

KeyEnv VariableDefaultDescription
tenant_idFASTCOMMENTS_TENANT_ID''Your FastComments tenant ID
api_keyFASTCOMMENTS_API_KEY''API key for server-side calls
regionFASTCOMMENTS_REGIONnullnull (US) or 'eu'
sso.enabledFASTCOMMENTS_SSO_ENABLEDfalseEnable SSO
sso.modeFASTCOMMENTS_SSO_MODE'secure''secure' or 'simple'
sso.login_urlFASTCOMMENTS_SSO_LOGIN_URLnullLogin URL (falls back to Laravel route)
sso.logout_urlFASTCOMMENTS_SSO_LOGOUT_URLnullLogout URL (falls back to Laravel route)
widget_defaults[]Default widget config options

Customizing Views Internal Link

To customize the Blade template:

php artisan vendor:publish --tag=fastcomments-views

Templates will be published to resources/views/vendor/fastcomments/.

Need Help?

If you encounter any issues or have questions about the Laravel Package, please:

Contributing

Contributions are welcome! Please visit the GitHub repository for contribution guidelines.