HeyLoyalty Laravel Helper
, (*1)
This is a package for Laravel 5 that allows easy management of a HeyLoyalty member list., (*2)
Features
- Subscribe
- Unsubscribe
- Update HeyLoyalty with latest data from Eloquent model
- Update custom fields
- Check subscription status
Installation
In your config/app.php
file, add this line to the list of providers:, (*3)
Hughwilly\HeyLoyalty\HeyLoyaltyProvider::class,
Optionally, you can add this line to the list of aliases:, (*4)
'HeyLoyalty' => Hughwilly\HeyLoyalty\Facades\HeyLoyalty::class
Finally, to get the config file, run this artisan command:, (*5)
php artisan vendor:publish --provider="Hughwilly\HeyLoyalty\HeyLoyaltyServiceProvider" --tag="config"
Configuration
The default config file looks like this:, (*6)
<?php
return [
'api_key' => null,
'secret' => null,
'list_id' => null
];
Get your api_key
and secret
from https://app.heyloyalty.com/settings/account and the list_id
from the list you want to manage., (*7)
Usage
This package includes a trait (SubscribesToHeyLoyalty
) to apply to your User model., (*8)
Apply this trait to by adding the following line at the top of the class:, (*9)
class User extends Model
{
use Hughwilly\HeyLoyalty\Traits\SubscribesToHeyLoyalty;
...
}
This trait will add functionality to subscribe, unsubscribe and update the associated member in HeyLoyalty., (*10)
Examples
Subscribing
Let's say you run a webshop, and your customer went through the checkout flow and accepted receiving newsletters., (*11)
On the receipt page, you could do this in the controller:, (*12)
public function receipt(Request $request, Order $order)
{
...
if ($order->subscribe_to_newsletter) {
$order->user->subscribe();
}
...
}
Updating
I recommend using Model Observers like so:, (*13)
class UserObserver
{
...
public function updating(User $user)
{
$user->updateHL();
}
}
And in your AppServiceProvider
:, (*14)
class AppServiceProvider extends ServiceProvider
{
public function boot()
{
User::observe(new UserObserver);
}
...
}
Contributing
Feel free to make any changes/additions., (*15)
Fork the repository and submit a pull request, then I'll take a look at your code whenever I can., (*16)