
์ธ์ด ๐ฐ๐ท ํ๊ตญ์ด
๋ฌธ์
์์ํ๊ธฐ
API ์ฐธ์กฐ
Add Comments to Your Laravel App
์ด๊ฒ์ FastComments์ ๊ณต์ Laravel ํจํค์ง์ ๋๋ค.
๋ผ์ด๋ธ ๋๊ธ, ์ฑํ ๋ฑ ๊ธฐ๋ฅ์ Laravel ์ ํ๋ฆฌ์ผ์ด์ ์ ์ถ๊ฐํ์ธ์.
์ ์ฅ์
์ค์น 
composer require fastcomments/laravel
๊ตฌ์ฑ ํ์ผ์ ๊ฒ์ํ์ธ์:
php artisan vendor:publish --tag=fastcomments-config
์๊ฒฉ ์ฆ๋ช
์ .env์ ์ถ๊ฐํ์ธ์:
FASTCOMMENTS_TENANT_ID=your-tenant-id
FASTCOMMENTS_API_KEY=your-api-key
EU ๋ฆฌ์ ์ ๊ฒฝ์ฐ:
FASTCOMMENTS_REGION=eu
Blade ์ปดํฌ๋ํธ 
๋๊ธ ์์ ฏ
<x-fastcomments />
{{-- ์ต์
ํฌํจ --}}
<x-fastcomments
url-id="my-page-id"
url="https://example.com/my-page"
locale="en_us"
:has-dark-background="true"
default-sort-direction="MR"
/>
๋ผ์ด๋ธ ์ฑํ
<x-fastcomments-live-chat url-id="chat-room-1" />
๋๊ธ ์
<x-fastcomments-comment-count url-id="my-page-id" />
<x-fastcomments-comment-count url-id="my-page-id" :number-only="true" />
SSO (์ฑ๊ธ ์ฌ์ธ์จ) 
๋น์ ์ .env์์ SSO๋ฅผ ํ์ฑํํ์ธ์:
FASTCOMMENTS_API_KEY=your-api-key
FASTCOMMENTS_SSO_ENABLED=true
FASTCOMMENTS_SSO_MODE=secure
๋ณด์ SSO์๋ API ํค๊ฐ ํ์ํฉ๋๋ค โ SSO ํ์ด๋ก๋๋ฅผ ์๋ช ํ๋ ๋ฐ ์ฌ์ฉ๋ฉ๋๋ค.
๊ตฌ์ฑ ๊ธฐ๋ฐ ๋งคํ
config/fastcomments.php์์ FastComments ํ๋๋ฅผ User ๋ชจ๋ธ ์์ฑ์ ๋งคํํ์ธ์:
'sso' => [
'enabled' => true,
'mode' => 'secure',
'user_map' => [
'id' => 'id',
'email' => 'email',
'username' => 'name',
'avatar' => 'profile.avatar_url', // ๋ํธ ํ๊ธฐ๋ฒ ์ง์
],
'is_admin' => fn ($user) => $user->hasRole('admin'),
'is_moderator' => fn ($user) => $user->hasRole('moderator'),
],
์ธํฐํ์ด์ค ๊ธฐ๋ฐ ๋งคํ
๋ ์ธ๋ฐํ ์ ์ด๋ฅผ ์ํด User ๋ชจ๋ธ์ MapsToFastCommentsUser ์ธํฐํ์ด์ค๋ฅผ ๊ตฌํํ์ธ์:
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'),
];
}
}
์ธํฐํ์ด์ค๊ฐ ๊ตฌํ๋์ด ์์ผ๋ฉด ๊ตฌ์ฑ ๊ธฐ๋ฐ ๋งคํ๋ณด๋ค ์ฐ์ ํฉ๋๋ค.
Blade์์์ SSO
SSO๊ฐ ํ์ฑํ๋๋ฉด <x-fastcomments /> ์ปดํฌ๋ํธ๊ฐ ์ธ์ฆ๋ ์ฌ์ฉ์์ ๋ํ SSO ๋ฐ์ดํฐ๋ฅผ ์๋์ผ๋ก ์ฃผ์
ํฉ๋๋ค.
API ์ก์ธ์ค 
ํผ์ฌ๋(Facade)๋ฅผ ํตํ ์ฌ์ฉ
use FastComments\Laravel\Facades\FastComments;
// ๊ด๋ฆฌ์ API (API ํค ํ์)
$comments = FastComments::admin()->getComments('tenant-id');
// ๊ณต๊ฐ API
$comments = FastComments::publicApi()->getCommentsPublic('tenant-id', 'url-id');
// SSO
$ssoPayload = FastComments::sso()->forWidget();
$token = FastComments::sso()->tokenFor($user);
์์กด์ฑ ์ฃผ์ (Dependency Injection)์ ํตํ ์ฌ์ฉ
use FastComments\Laravel\FastCommentsManager;
class CommentController extends Controller
{
public function index(FastCommentsManager $fc)
{
$comments = $fc->admin()->getComments($fc->tenantId());
// ...
}
}
SDK์ ์ง์ ์ ๊ทผ
use FastComments\Client\Api\DefaultApi;
class CommentController extends Controller
{
public function index(DefaultApi $api)
{
$comments = $api->getComments('tenant-id');
// ...
}
}
์ค์ ์ฐธ์กฐ 
| ํค | ํ๊ฒฝ ๋ณ์ | ๊ธฐ๋ณธ๊ฐ | ์ค๋ช |
|---|---|---|---|
tenant_id |
FASTCOMMENTS_TENANT_ID |
'' |
๊ทํ์ FastComments ํ ๋ํธ ID |
api_key |
FASTCOMMENTS_API_KEY |
'' |
์๋ฒ ์ธก ํธ์ถ์ฉ API ํค |
region |
FASTCOMMENTS_REGION |
null |
null (๋ฏธ๊ตญ) ๋๋ 'eu' |
sso.enabled |
FASTCOMMENTS_SSO_ENABLED |
false |
SSO ํ์ฑํ |
sso.mode |
FASTCOMMENTS_SSO_MODE |
'secure' |
'secure' ๋๋ 'simple' |
sso.login_url |
FASTCOMMENTS_SSO_LOGIN_URL |
null |
๋ก๊ทธ์ธ URL (Laravel ๋ผ์ฐํธ๋ก ๋์ฒด๋จ) |
sso.logout_url |
FASTCOMMENTS_SSO_LOGOUT_URL |
null |
๋ก๊ทธ์์ URL (Laravel ๋ผ์ฐํธ๋ก ๋์ฒด๋จ) |
widget_defaults |
โ | [] |
๊ธฐ๋ณธ ์์ ฏ ๊ตฌ์ฑ ์ต์ |
| --- |
๋์์ด ํ์ํ์ ๊ฐ์?
Laravel ํจํค์ง์ ๊ดํด ๋ฌธ์ ๊ฐ ๋ฐ์ํ๊ฑฐ๋ ์ง๋ฌธ์ด ์๋ ๊ฒฝ์ฐ, ๋ค์์ ์ด์ฉํด ์ฃผ์ธ์:
๊ธฐ์ฌ
๊ธฐ์ฌ๋ฅผ ํ์ํฉ๋๋ค! ๊ธฐ์ฌ ์ง์นจ์ GitHub ์ ์ฅ์๋ฅผ ๋ฐฉ๋ฌธํ์ธ์.