Downloads
Stars
Version
Laravel-Kuainiu incorporates Kuainiu Connect and the Kuainiu API into your Laravel
Add Laravel-Kuainiu to your composer file via the composer require
command:
$ composer require kuainiu/laravel-kuainiu
Or add it to composer.json
manually:
"require": {
"kuainiu/laravel-kuainiu": "~1.0"
}
To get started, you'll need to publish all vendor assets:
$ php artisan vendor:publish --provider="Kuainiu\KuainiuServiceProvider"
This will create a config/kuainiu.php
file in your app that you can modify to set your configuration.
If you intend on using Kuainiu Connect, update config/services.php
by adding this to the array:
'kuainiu' => [
'oauthServerDomain' => env('KUAINIU_OAUTH_DOMAIN'),
'client_id' => env('KUAINIU_CLIENT_ID', 'app_xxx'),
'client_secret' => env('KUAINIU_CLIENT_SECRET'),
'redirect' => env('KUAINIU_REDIRECT_URI'),
],
To make sure Laravel Socialite can actually find the Kuainiu driver, use the following code snippet and paste it in the boot()
method from your AppServiceProvider.php
.
Socialite::extend('kuainiu', function ($app) {
$config = $app['config']['services.kuainiu'];
return Socialite::buildProvider('Kuainiu\KuainiuConnectProvider', $config);
});
Here you can see an example of just how simple this package is to use.
$user = Kuainiu::api()->user()->create([
"name" => 'user_name_',
"mobile" => "13800138000"
]);
$user = Kuainiu::createUser(['name'=>'name']);
if ($user->isCreated())
{
echo "User Created.";
}
Route::get('login', function () {
return Socialite::with('kuainiu')
->scopes('profiles.read profiles.write') // Additional permission: profiles.read profiles.write(the string need space separator)
->redirect();
});
Route::get('kuainiu/user/auth', function () {
$user = Socialite::with('kuainiu')->stateless()->user();
dd($user);
});
Copyright (c) 2018, Kuainiu Group