ezavalishin/vkma is a Laravel package for :package_description.
It currently has 0 GitHub stars and 290 downloads on Packagist (latest version 0.1.9).
Install it with composer require ezavalishin/vkma.
Discover more Laravel packages by ezavalishin
or browse all Laravel packages to compare alternatives.
Last updated
This is where your description should go. Take a look at contributing.md to see a to do list.
Via Composer
$ composer require ezavalishin/vkma
Publish config
$ php artisan vendor:publish --provider="ezavalishin\VKMA\VKMAServiceProvider"
Package provides auth driver vkma
You can put it in your config/auth.php
'guards' => [
...
'vkma' => [
'driver' => 'vkma'
]
],
Guard get or create user in your db by vk_user_key
Next you can use middleware auth:vkma and send request with header Vk-Params base64 encoded vk launch params
Javascript
let instance = axios.create({
headers: {
common: { // can be common or any other method
'Vk-Params': btoa(window.location.search.substring(1))
}
}
})
Laravel
$user = Auth::user();
Package provides Job FillUser which filling your db with data from vk
You should implement VKMAUserInterface and use trait VKMAUserable also map vk fields
use Illuminate\Foundation\Auth\User as Authenticatable;
use ezavalishin\VKMA\Contracts\VKMAUserInterface;
use ezavalishin\VKMA\Traits\VKMAUserable;
class User extends Authenticatable implements VKMAUserInterface
{
use VKMAUserable;
public function vkFieldsMap(): array
{
return [
//db field => vk field name
'first_name' => 'first_name',
'last_name' => 'last_name',
'birth_date' => 'bdate',
'city_id' => 'city',
'country_id' => 'country'
];
}
}
Now you can easily fill your user model just dispatch job
dispatch(new \ezavalishin\VKMA\Jobs\FillUser($user));
Or you can do it when user created, just add in your model:
use Illuminate\Foundation\Auth\User as Authenticatable;
use ezavalishin\VKMA\Contracts\VKMAUserInterface;
use ezavalishin\VKMA\Traits\VKMAUserable;
use ezavalishin\VKMA\Jobs\FillUser;
class User extends Authenticatable implements VKMAUserInterface
{
use VKMAUserable;
...
public static function booted()
{
self::created(static function(self $model) {
dispatch(new FillUser($model));
});
}
}
When job fetch field from vk you can easily change its format
Add in your model public method parse{VkFieldName}(camel case) and return value which will be stored in db
Example:
use Illuminate\Foundation\Auth\User as Authenticatable;
use ezavalishin\VKMA\Contracts\VKMAUserInterface;
use ezavalishin\VKMA\Traits\VKMAUserable;
class User extends Authenticatable implements VKMAUserInterface
{
use VKMAUserable;
...
public function parseCountry($value)
{
return $value['id'];
}
public function parseCity($value)
{
return $value['id'];
}
}
Please see the changelog for more information on what has changed recently.
$ composer test
Please see contributing.md for details and a todolist.
If you discover any security related issues, please email [email protected] instead of using the issue tracker.
MIT. Please see the license file for more information.