PHP code example of dutchcodingcompany / filament-socialite
1. Go to this page and download the library: Download dutchcodingcompany/filament-socialite library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
dutchcodingcompany / filament-socialite example snippets
use Laravel\Socialite\Contracts\User as SocialiteUserContract;
use Illuminate\Contracts\Auth\Authenticatable;
// ...
->plugin(
FilamentSocialitePlugin::make()
// ( 'icon' => 'fab-github',
// (optional) Button color override, default: 'gray'.
'color' => 'primary',
// (optional) Button style override, default: true (outlined).
'outlined' => false,
],
])
// (optional) Enable/disable registration of new (socialite-) users.
->setRegistrationEnabled(true)
// (optional) Enable/disable registration of new (socialite-) users using a callback.
// In this example, a login flow can only continue if there exists a user (Authenticatable) already.
->setRegistrationEnabled(fn (string $provider, SocialiteUserContract $oauthUser, ?Authenticatable $user) => (bool) $user)
// (optional) Change the associated model class.
->setUserModelClass(\App\Models\User::class)
// (optional) Change the associated socialite class (see below).
->setSocialiteUserModelClass(\App\Models\SocialiteUser::class)
);
namespace App\Models;
use DutchCodingCompany\FilamentSocialite\Models\Contracts\FilamentSocialiteUser as FilamentSocialiteUserContract;
use Illuminate\Contracts\Auth\Authenticatable;
use Laravel\Socialite\Contracts\User as SocialiteUserContract;
class SocialiteUser implements FilamentSocialiteUserContract
{
public function getUser(): Authenticatable
{
//
}
public static function findForProvider(string $provider, SocialiteUserContract $oauthUser): ?self
{
//
}
public static function createForProvider(
string $provider,
SocialiteUserContract $oauthUser,
Authenticatable $user
): self {
//
}
}
use DutchCodingCompany\FilamentSocialite\Models\Contracts\FilamentSocialiteUser as FilamentSocialiteUserContract;
use DutchCodingCompany\FilamentSocialite\Models\SocialiteUser;
FilamentSocialite::setLoginRedirectCallback(function (string $provider, FilamentSocialiteUserContract $socialiteUser) {
return redirect()->intended(
route(FilamentSocialite::getPlugin()->getDashboardRouteName())
);
});
## in Service Provider file
public function boot()
{
//...
Filament::registerRenderHook(
'filament-fortify.login.end',
fn (): string => Blade::render('<x-filament-socialite::buttons />'),
);
}