composer require lartie/attach-social-account
Add the package to your application service providers in config/app.php
file.
'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,
],
Publish the package config file and migrations to your application. Run these commands inside your terminal.
php artisan vendor:publish
And also run migrations.
php artisan migrate
This uses the default users table which is in Laravel. You should already have the migration file for the users table available and migrated.
Include HasSocialAccount
trait and also implement HasSocialAccount
contract inside your User
model.
use LArtie\AttachSocialAccount\Core\Traits\HasSocialAccount;
use LArtie\AttachSocialAccount\Core\Contracts\HasSocialAccount as HasSocialAccountContract;
class User extends Authenticatable implements HasSocialAccountContract
{
use HasSocialAccount;
And that's it!
$user = User::first();
$vkData = [
'token' => 'token',
'uid' => 'user_id',
'nickname' => 'username',
'name' => 'first name and last name',
'email' => 'example@gmail.com',
'avatar' => 'link_to',
];
$socialNetwork = SocialNetworks::create([
'provider' => 'vkontakte',
'short_name' => 'vk'
]);
$user->attachSocialAccountById($socialNetwork->id, $vkData);
or
$user->attachSocialAccountByShortName('vk', $vkData);
or
$user->attachSocialAccountByProvider('vkontakte', $vkData);
$user->detachSocialAccountById($socialNetwork->id);
or
$user->detachSocialAccountByShortName('vk');
or
$user->detachSocialAccountByProvider('vkontakte');
$user->hasSocialAccountById($socialNetwork->id);
or
$user->hasSocialAccountByShortName('vk');
or
$user->hasSocialAccountByProvider('vkontakte');
@providerExists('vkontakte') {
// see detach button, etc..
}
@providerNotExists('vkontakte') {
// see attach button, etc..
}
For more information visit trait
HasSocialAccount
or contractHasSocialAccount
This package is free software distributed under the terms of the MIT license.