PHP code example of humweb / sociable

1. Go to this page and download the library: Download humweb/sociable 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/ */

    

humweb / sociable example snippets


 Humweb\Sociable\ServiceProvider::class
 



// config/sociable.php

return [

    // Builtin options: laravel, sentinel
    'auth_provider' => 'laravel',

    // Optional provider list, mainly used to list login buttons.
    'providers' => [
        'google',
        'github',
        'twitter'
    ]
];

class User extends Authenticatable
{
    use Sociable;
}



class AuthController extends Controller
{
    /**
     * Login
     */
    public function getLogin(Request $request)
    {

        // Remove social data from session upon request
        if ($request->exists('forget_social')) {
            $request->session()->forget('social_link');
        }

        return view('login');
    }


    public function postLogin(Request $request)
    {

        // Gather credentials
        $credentials = [
            'username' => $request->get('username'),
            'password' => $request->get('password'),
        ];

        if ($user = \Auth::attempt($credentials, $remember)) {

            // Check for social data in session
            if ($request->session()->has('social_link')) {

                // Grab data from session
                $social = $request->session()->get('social_link');
                $user->attachProvider($social['provider'], $social);

                // Remove link data
                $request->session()->forget('social_link');

                return redirect()
                    ->intended('/')
                    ->with('success', 'Account connected to "'.$social['provider'].'" successfully.');
            }

            return redirect()->intended('/');
        }

        // Default error message
        return back()
            ->withInput()
            ->withErrors('Invalid login or password.');
    }

}
bash  
$ php artisan vendor:publish --provider="Humweb\Sociable\ServiceProvider"
bash  
$ php artisan migrate"