PHP code example of lartie / attach-social-account

1. Go to this page and download the library: Download lartie/attach-social-account 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/ */

    

lartie / attach-social-account example snippets


'providers' => [
    
    /*
     * Application Service Providers..
     */
    App\Providers\AppServiceProvider::class,
    App\Providers\AuthServiceProvider::class,
    App\Providers\EventServiceProvider::class,
    App\Providers\RouteServiceProvider::class,
    ...
    
    /*
     * Extensions
     */
    LArtie\AttachSocialAccount\ServiceProvider::class,

],

use LArtie\AttachSocialAccount\Core\Traits\HasSocialAccount;
use LArtie\AttachSocialAccount\Core\Contracts\HasSocialAccount as HasSocialAccountContract;

class User extends Authenticatable implements HasSocialAccountContract
{
    use HasSocialAccount;

 $user = User::first();
 
 $vkData = [
     'token' => 'token',
     'uid' => 'user_id',
     'nickname' => 'username',
     'name' => 'first name and last name',
     'email' => '[email protected]',
     'avatar' => 'link_to',
 ];

$socialNetwork = SocialNetworks::create([
    'provider' => 'vkontakte', 
    'short_name' => 'vk'
]);

$user->attachSocialAccountById($socialNetwork->id, $vkData);

$user->attachSocialAccountByShortName('vk', $vkData);

$user->attachSocialAccountByProvider('vkontakte', $vkData);

$user->detachSocialAccountById($socialNetwork->id);

$user->detachSocialAccountByShortName('vk');

$user->detachSocialAccountByProvider('vkontakte');

$user->hasSocialAccountById($socialNetwork->id);

$user->hasSocialAccountByShortName('vk');

$user->hasSocialAccountByProvider('vkontakte');

@providerExists('vkontakte') {
// see detach button, etc..
}

@providerNotExists('vkontakte') {
// see attach button, etc.. 
}