Larascord can be installed in a new application or in an application that already has a users table, authentication and views.
Install Larascord using Composer
composer require jakyeru/larascordRun the installation command
php artisan larascord:installThe command asks for your Discord application's credentials, writes them to the .env file, publishes the configuration file and the migrations, and runs them.
Add a link to the login route
<a href="{{ route('larascord.redirect') }}">Log in with Discord</a>You can get your Discord application's CLIENT ID and CLIENT SECRET from the OAuth2 tab of your application.
Installed files
| Type | Location |
|---|---|
| Configuration | config/larascord.php |
| Migrations | database/migrations |
| Tables | larascord_accounts, larascord_access_tokens |
| Routes | The configured prefix, named with a larascord. prefix |
User resolution
The Discord profile is stored in the larascord_accounts table and linked to your user model through a user_id foreign key.
On the callback, the user is resolved in the following order:
A linked Discord account
The account matching the Discord ID is looked up in larascord_accounts. If it has a user_id, that user is logged in.
An existing user with the same e-mail address
The e-mail address of the Discord account is matched against the column set in users.email_column. Controlled by the users.link_by_email option.
A new user
A user is created from the users.attributes mapping. Controlled by the users.create_missing option.
If no user is resolved, the request is redirected with the registration_disabled error message.
Attribute mapping
The users.attributes option maps the columns of your users table to the attributes of the Discord profile.
'users' => [
'model' => App\Models\User::class,
'email_column' => 'email',
'attributes' => [
'name' => 'display_name',
'email' => 'email',
],
'link_by_email' => true,
'create_missing' => true,
'fill_random_password' => true,
],The available attributes are id, username, global_name, display_name, discriminator, avatar, email, verified, banner, banner_color, accent_color, locale, mfa_enabled, premium_type and public_flags.
display_name returns global_name and falls back to username when the account has no global display name.
When users.fill_random_password is enabled and the users table has a password column that is not present in the mapping, the column is filled with a hashed random string.
Custom resolver
Register a callback in the boot method of a service provider to resolve the user yourself. It receives the Discord profile and returns an Authenticatable, or null to reject the login.
use Jakyeru\Larascord\Facades\Larascord;
use Jakyeru\Larascord\Types\User as DiscordUser;
public function boot(): void
{
Larascord::resolveUsersUsing(function (DiscordUser $discordUser) {
return User::firstOrCreate(['email' => $discordUser->email], [
'name' => $discordUser->display_name,
'team_id' => Team::default()->id,
]);
});
}Linking an existing user
An authenticated user can link a Discord account through the larascord.link route. The Discord account is attached to the authenticated user instead of resolving a new one.
@if (auth()->user()->hasDiscordAccount())
<form method="POST" action="{{ route('larascord.unlink') }}">
@csrf
@method('DELETE')
<button>Unlink Discord</button>
</form>
@else
<a href="{{ route('larascord.link') }}">Link Discord</a>
@endifhasDiscordAccount() is provided by the InteractsWithDiscord trait. Without the trait, use Jakyeru\Larascord\Models\DiscordAccount::forUser($user).
The InteractsWithDiscord trait
The trait is optional. It adds the discordAccount relationship and the methods documented in InteractsWithDiscord Trait to your user model.
namespace App\Models;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Jakyeru\Larascord\Traits\InteractsWithDiscord;
class User extends Authenticatable
{
use InteractsWithDiscord;
}The login route alias
Laravel's auth middleware redirects guests to a route named login. Larascord registers one when LARASCORD_LOGIN_ALIAS is enabled.
LARASCORD_LOGIN_ALIAS=trueKeep this disabled if your application already registers a route named login. The route registered last takes precedence.
Uninstalling
Roll back the migrations
php artisan migrate:rollback --path=database/migrations/2026_01_01_000001_create_larascord_access_tokens_table.phpphp artisan migrate:rollback --path=database/migrations/2026_01_01_000000_create_larascord_accounts_table.phpRemove the package
composer remove jakyeru/larascordDelete the remaining files
config/larascord.php- The two migration files
- The
InteractsWithDiscordtrait, if it was added to your user model