
Lingua 🇮🇹 Italiano
Documentazione
Primi passi
Riferimento API
Add Comments to Your Laravel App
Questo è il pacchetto Laravel ufficiale per FastComments.
Aggiungi commenti in tempo reale, chat e altro alla tua applicazione Laravel.
Repository
Installazione 
composer require fastcomments/laravel
Pubblica il file di configurazione:
php artisan vendor:publish --tag=fastcomments-config
Aggiungi le tue credenziali in .env:
FASTCOMMENTS_TENANT_ID=your-tenant-id
FASTCOMMENTS_API_KEY=your-api-key
Per la regione UE:
FASTCOMMENTS_REGION=eu
Componenti Blade 
Widget dei commenti
<x-fastcomments />
{{-- Con opzioni --}}
<x-fastcomments
url-id="my-page-id"
url="https://example.com/my-page"
locale="en_us"
:has-dark-background="true"
default-sort-direction="MR"
/>
Chat dal vivo
<x-fastcomments-live-chat url-id="chat-room-1" />
Conteggio commenti
<x-fastcomments-comment-count url-id="my-page-id" />
<x-fastcomments-comment-count url-id="my-page-id" :number-only="true" />
SSO 
Abilita SSO nel tuo .env:
FASTCOMMENTS_API_KEY=your-api-key
FASTCOMMENTS_SSO_ENABLED=true
FASTCOMMENTS_SSO_MODE=secure
La chiave API è richiesta per l'SSO sicuro — viene usata per firmare il payload SSO.
Mappatura basata sulla configurazione
In config/fastcomments.php, mappa i campi di FastComments agli attributi del tuo modello User:
'sso' => [
'enabled' => true,
'mode' => 'secure',
'user_map' => [
'id' => 'id',
'email' => 'email',
'username' => 'name',
'avatar' => 'profile.avatar_url', // notazione a punti supportata
],
'is_admin' => fn ($user) => $user->hasRole('admin'),
'is_moderator' => fn ($user) => $user->hasRole('moderator'),
],
Mappatura basata sull'interfaccia
Per un maggiore controllo, implementa l'interfaccia MapsToFastCommentsUser nel tuo modello User:
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'),
];
}
}
Quando l'interfaccia è implementata, ha la precedenza sulla mappatura basata sulla configurazione.
SSO in Blade
Quando l'SSO è abilitato, il componente <x-fastcomments /> inserisce automaticamente i dati SSO per l'utente autenticato.
Accesso alle API 
Tramite Facade
use FastComments\Laravel\Facades\FastComments;
// Admin API (richiede la chiave API)
$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);
Tramite Dependency Injection
use FastComments\Laravel\FastCommentsManager;
class CommentController extends Controller
{
public function index(FastCommentsManager $fc)
{
$comments = $fc->admin()->getComments($fc->tenantId());
// ...
}
}
Accesso diretto allo SDK
use FastComments\Client\Api\DefaultApi;
class CommentController extends Controller
{
public function index(DefaultApi $api)
{
$comments = $api->getComments('tenant-id');
// ...
}
}
Riferimento alla configurazione 
| Chiave | Variabile d'ambiente | Predefinito | Descrizione |
|---|---|---|---|
tenant_id |
FASTCOMMENTS_TENANT_ID |
'' |
Il tuo ID tenant di FastComments |
api_key |
FASTCOMMENTS_API_KEY |
'' |
Chiave API per chiamate lato server |
region |
FASTCOMMENTS_REGION |
null |
null (US) o 'eu' |
sso.enabled |
FASTCOMMENTS_SSO_ENABLED |
false |
Abilita SSO |
sso.mode |
FASTCOMMENTS_SSO_MODE |
'secure' |
'secure' o 'simple' |
sso.login_url |
FASTCOMMENTS_SSO_LOGIN_URL |
null |
URL di login (in alternativa usa la route di Laravel) |
sso.logout_url |
FASTCOMMENTS_SSO_LOGOUT_URL |
null |
URL di logout (in alternativa usa la route di Laravel) |
widget_defaults |
— | [] |
Opzioni di configurazione predefinite del widget |
| --- |
Hai bisogno di aiuto?
Se riscontri problemi o hai domande sul pacchetto Laravel, per favore:
Contribuire
I contributi sono benvenuti! Visita il repository GitHub per le linee guida sui contributi.