Skip to content
No description or website provided.
PHP
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
database/migrations
src
tests
.editorconfig
.gitattributes
.gitignore
.travis.yml
LICENSE
README.md
composer.json
phpunit.xml.dist
renovate.json

README.md

Laravel Sociable

Build Status PHP from Packagist Latest Version License

Installation

Require this package, with Composer, in the root directory of your project.

$ composer require artisanry/sociable

Migration

To get started, you'll need to publish all vendor assets:

$ php artisan vendor:publish --provider="Artisanry\Sociable\SociableServiceProvider"

And then run the migrations to setup the database table.

$ php artisan migrate

Usage

Setup a Model
namespace App;

use Artisanry\Sociable\Sociable;
use Illuminate\Database\Eloquent\Model;

class User extends Model
{
    use Sociable;
}
Authenticating a User
use Artisanry\Sociable\Services\Authenticator;
use Artisanry\Sociable\Events\UserHasSocialized;

$router->get('/', function (Authenticator $authenticate, Request $request) {
    return $authenticate->provider('github') // authenticate with github
                        ->model(User::class) // this can also be a model like User::find(1) if you want to attach multiple social profiles to one model
                        ->mapField('username', 'nickname') // map the nickname field to the username column on the user model
                        ->mapField('email', 'email') // map the email field to the email column on the user model
                        ->mapField('avatar', 'avatar') // map the avatar field to the avatar column on the user model
                        ->mapField('password', bcrypt(str_random(10)), true) // add an additional password field to the user model
                        ->event(UserHasSocialized::class) // this event will be fired after the user profile has been retrieved
                        ->execute($request->has('code')); // if no code is available we will redirect instead of processing the response
});
Default Event

The default event that is fired is UserHasSocialized which will take care of creating and updating all models.

Custom Event

If you need to have your own way of handling the response take a look at UserHasSocialized and UserHasSocializedListener and create your event and listener.

Once you've done that you can just use ->event(MyCustomEvent::class) and the response will be passed through to your event.

Testing

$ phpunit

Security

If you discover a security vulnerability within this package, please send an e-mail to hello@basecode.sh. All security vulnerabilities will be promptly addressed.

Credits

This project exists thanks to all the people who contribute.

License

Mozilla Public License Version 2.0 (MPL-2.0).

You can’t perform that action at this time.